DateTime.Parse vs Convert.ToDateTime

S-Soft 646 Reputation points


As most of the times I cannot reply to my own threads, in continue of:

I need to get date and time from a custom date time control and save it into registry, then load it back to the control.

That's the best method to parse the string back to DateTime?


What about Convert.ToDateTime(now2) compared to DateTime.Parse?

Convert.ToDateTime seems to work too, but which one is better to avoid possible exceptions?

Thanks all

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
9,467 questions
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,401 questions
{count} votes

Accepted answer
  1. P a u l 9,976 Reputation points

    There's not much difference, you can even see the difference if you decompile the source/lookup the C# reference source online.

    The main difference is that is coalesces a null input to a new DateTime(0) (i.e. DateTime.MinValue) which feels a bit wonky to me.

    User's image

    Apart from that the only other difference is that you can't pass DateTimeStyles like you can with DateTime.Parse / DateTime.TryParse so the resulting DateTime will always represent the date in Local time rather than Utc.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful