Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# strange with DateTime

Tags:

c#

datetime

utc

I got some strange result for:

Console.WriteLine(new DateTime(1296346155).ToString());

Result is:

01.01.0001 0:02:09

But it is not right!

I parsed value 1296346155 from some file. It said that it is in UTC;

Please explain;)

Thank you for help!)))

like image 931
Edward83 Avatar asked Mar 17 '26 20:03

Edward83


2 Answers

DateTime expects "A date and time expressed in the number of 100-nanosecond intervals that have elapsed since January 1, 0001 at 00:00:00.000 in the Gregorian calendar." (from msdn)

This question shows how you can convert a unix timestamp to a DateTime.

like image 52
Twelve47 Avatar answered Mar 19 '26 08:03

Twelve47


The constructor for DateTime that accept long type is expecting ticks value, not seconds or even milliseconds, and not from 1/1/1970 like in other languages.

So 1296346155 ticks is 129 seconds.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!