Reg - DateTime.ToFileTime() having Bug..

  • Thread starter Thread starter rajesh_s76
  • Start date Start date
R

rajesh_s76

Hi Gurus,

i am facing problem using ToFileTime() function in DateTime Cass.
1. I set the Date in st;
DateTime st = new DateTime(2006,05,22);

2. i created new datetime variable
DateTime ft = new DateTime();

3.// i assign the st into ft.
ft = st;
4. // Converting to FileTime, its returing long value.
long lVal1 = ft.ToFileTime();

5. for cross checking that Long is correct format or not.
DateTime ft2 = new DateTime( lVal1 );

The problem was date is coming in wrong value.
ft = 22/05/406.

i really dont know it suppose to come 22/05/2006. why it is coming
wrong year?..

is there any problem in my code?..

Kindly clear my code bugs...

Thanks & Regards,
Rajesh. S
 
You're doing a number of minor things that don't make sense:

2. Why? If your next step is to assign ft = st, what's the point of doing
new DateTime()?

5. This constructor doesn't do what you think it does. Read the help on the
constructor you're using here. What you really want is FromFileTime(), a
static method that returns a DateTime object from a given file time.

You could use st.Ticks and create a new DateTime using *that* Long value and
you should get the same date represented back, but you shouldn't mix file
times and ticks. Also note the following comment in the .NET CF 2.0 help:

Previous versions of the ToFileTime method assume the current DateTime
object is a local time. Starting with the.NET Framework version 2.0, the
ToFileTime method uses the Kind property to determine whether the current
DateTime object is a local time, a UTC time, or an unspecified kind of time
which is treated as a local time.

So, you should use the Kind property to assure that the conversion you are
doing is the one you mean to do.

Paul T.
 
Back
Top