JL.
JL.

Reputation: 81292

Convert.ToDateTime , any way to depict month and year fields C#?

I have the following wonderfully unreliable statement:

  string LastsuccessfuldownloadDateTime = "04.07.2009 19:21:36"
  DateTime myDate = Convert.ToDateTime(LastsuccessfuldownloadDateTime);

Is it possible to depict the day and month fields explicitly in the conversion? Because my month and day fields are getting swapped....

Thanks

Upvotes: 1

Views: 1633

Answers (1)

Philippe Leybaert
Philippe Leybaert

Reputation: 171794

You can use DateTime.ParseExact():

// for European format (day followed by month)
DateTime myDate = DateTime.ParseExact(LastsuccessfuldownloadDateTime , 
                                      "dd.MM.yyyy HH:mm:ss", null);

Upvotes: 12

Related Questions