How to convert WinCE "FILETIME" to System.DateTime-format?

  • Thread starter Danyel Meyer - dialog-it GmbH
  • Start date
D

Danyel Meyer - dialog-it GmbH

Hallo!

Could anyone tell me how to convert a time given in a FILETIME structure
during P/Invoke to a DateTime value in VB.NET?
I´ve tried functions like DateTime.FromFileTime(), but what I get does not
match the time that should be it...

Many thanks in advance,

--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
P

Peter Foot [MVP]

Have you tried FromFileTimeUTC() which will convert a time expressed as
universal time (FromFileTime expects a FileTime expressed in the devices
currently set local time)

Peter
 
D

Danyel Meyer - dialog-it GmbH

Hallo Peter,

Yes, I´ve already tried this, but it also gives a value that is hundreds of
years behind.
I´ve just tried to use coredll.dll´s FileTimeToSystemTime, because the WinCE
SYSTEMTIME structure looks more usable, but I get a NotSupportedException...

Hope anyone knows a way to get it done...


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
D

Danyel Meyer - dialog-it GmbH

Okay, it was ByVal where it should have been ByRef... works now, I think I
can use the SYSTEMTIME-structured format.


--
Danyel Meyer
-------------------------------------------
dialog-it GmbH
Röllinghäuser Strasse 55a
31061 Alfeld/Leine

Tel +49 (0) 5181 900 814
Fax +49 (0) 5181 900 815
E-Mail danyel.meyer <at> dialog-it.de
 
A

Alex Feinman [MVP]

struct FILETIME
{
int lo;
int hi;
}

FILETIME ft;
....
DateTime dt = DateTime.FromFileTimeUtc((((long)ft.hi) << 32) | ft.lo);

or in VB

Struct FileTime
Lo as Integer,
Hi as Integer
End Struct

Dim dt as DateTime = DateTime.FromFileTimeUtc( (CLng(ft.Hi) SHL 32) OR
ft.Lo)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top