Converting E MMM dd HH:mm:ss Z yyyy to dd/MM/yyyy HH:mm:ss c#

Asked

Viewed 345 times

1

I’m getting the following date Thu Sep 01 00:00:00 BRT 2016 and need to convert to dd/MM/yyyy HH:mm:ss

Only that the Convert generates error, I’m receiving this date via string of a System.

Can someone help me?

DateTime dtPeca;
dtPeca = Convert.ToDateTime(linha[4]);

1 answer

2


If you are sure that the format will always be the same, you can make the conversion using TryParseExact

DateTime dateValue;
DateTime.TryParseExact(data, "ddd MMM dd hh:mm:ss BRT yyyy", new CultureInfo("en-US"), 
                       DateTimeStyles.None, out dateValue);
  • Yes the Date is always in this format, so I have to do the conversion. that "date" I put the value I get ?

  • @Renansilveira Yes, because that’s what I did in my answer.

  • the output value of dateValue is the initial value (01/01/0001), it does not take the converted value.

  • @So it is because the input string is not format that you posted in the question =)

  • "Sun Jan 01 00:00:00 BRST 2017" That’s the amount I collect

  • @Compare with the value you put in the question and will see the difference. Then just adapt in the answer and everything will work normally.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.