strange thing about DateTime

  • Thread starter Thread starter Justin Shen
  • Start date Start date
J

Justin Shen

i wrote following code:

DateTime t1 = new DateTime( DateTime.Today.ToFileTime() );
Console.WriteLine(t1);

and got a output of:
0404-5-3 16:00:00
instead of 2004-5-3 16:00:00

why could this happen?
 
Justin said:
i wrote following code:

DateTime t1 = new DateTime( DateTime.Today.ToFileTime() );
Console.WriteLine(t1);

and got a output of:
0404-5-3 16:00:00
instead of 2004-5-3 16:00:00

why could this happen?

The ToFileTime() function returns a long value that represents the
number of 100-nanosecond units since 12:00 AM January 1st 1601.

However, you're then using the constructor for DateTime that's expecting
the number of 100-nanosecond units since 12:00 AM January 1st 1 A.D.
 
Ed said:
The ToFileTime() function returns a long value that represents the
number of 100-nanosecond units since 12:00 AM January 1st 1601.

However, you're then using the constructor for DateTime that's expecting
the number of 100-nanosecond units since 12:00 AM January 1st 1 A.D.

I forgot to add; re-write your original code to:

DateTime t1 = DateTime.FromFileTime(DateTime.Today.ToFileTime());
Console.WriteLine(t1);
 
Back
Top