locked
Epoch time conversion to System Time and Date RRS feed

  • Question

  • Hi,

     I want to convert Epoch time to System Time and Date format, I checked Windows Mobile 6.5.3 documentation, I didn't find any API which does this conversion from Epoch Seconds to Date & Time!  

     I will appreciate your help if you can point me to some link where this implementation is defined or if Windows Mobile 6.5.3 does this with any API if so I am missing to look in.

     I am aware this can be done using C# but my problem is focused on VC++ implementation.

    Thanks.

     

    Monday, July 12, 2010 9:21 AM

Answers

  • It's not any special API calls, just addition, subtraction, division, and multiplication. Do the conversion operation detailed in the link in reverse order and you should be able to go from timeval to FILETIME. Then, just use FileTimeToSystemTime() to convert to a SYSTEMTIME structure.

    If you're having a specific problem with the mathematics, let me know and I'll try to help.

    -PaulH

    Wednesday, July 14, 2010 9:45 PM

All replies

  • Hi,

    Here is a C/C++ answer:

     

    time_t timeNow;
    timeNow = time( &timeNow );
    
    struct tm *ptmTimeNow;
    ptmTimeNow = gmtime(&timeNow);

    Hmm -- Sorry I just realized that gmtime will compile, but will not link. The binary is not included in WM-6. I've been working with MFC and it has a solution.

    Cheers,

    Monte---

    • Edited by RumJungle Monday, July 12, 2010 2:45 PM corrected code
    Monday, July 12, 2010 2:42 PM
  • I'm a bit late since you have a working solution. But, if you would rather not use MFC, then

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/430449b3-f6dd-4e18-84de-eebd26a8d668

     

    -PaulH

     

    Monday, July 12, 2010 4:49 PM
  • Paul, 

     

     The link which you have provided gives conversion from system time to Epoch time, but what I asked is conversion from Epoch time to System time, kindly notify me if there is any API in Windows Mobile 6.5.3 using VC++ I can achive this !

    Thanks,

    Wednesday, July 14, 2010 6:25 AM
  • It's not any special API calls, just addition, subtraction, division, and multiplication. Do the conversion operation detailed in the link in reverse order and you should be able to go from timeval to FILETIME. Then, just use FileTimeToSystemTime() to convert to a SYSTEMTIME structure.

    If you're having a specific problem with the mathematics, let me know and I'll try to help.

    -PaulH

    Wednesday, July 14, 2010 9:45 PM
  • Your answer focuses on the current date/time. What if the Epoch date/time is anything else such as 1464545562043
    Friday, January 27, 2017 12:49 PM
  • Thinking in epoch definition, this is a simple way under Microsoft world:

    DateAdd(DateInterval.Second, 1335461556, Date.Parse("1970-01-01 00:00"))

    1970 date must be fixed, as it is the definition of epoch.

    I know this post is old, but still useful.

    • Proposed as answer by Bruce Eitman Friday, July 13, 2018 6:42 PM
    Friday, July 13, 2018 5:50 PM
  • Chema

    That is nice, but what is the hard coded value 1335461556?  I assume that it is the epoch value for some time - but you don't say, so your answer is confusing.

    Seems like you mean the following, am I correct?

    double EpocSeconds = (double)1335461556;  // GMT: Thursday, April 26, 2012 5:32:36 PM

    DateTime SystemSeconds = DateAdd(DateInterval.Second, EpocSeconds, Date.Parse("1970-01-01 00:00"))

    MessageBox.Show("System Date and Time: " + SystemSeconds .ToShortDateString() + " " + SystemSeconds .ToShortTimeString() )

    Output - although this would really be in the local time for the system

    System Date and Time: 4/26/2012 5:32 PM


    Bruce Eitman
    Senior Enginer
    Bruce.Eitman AT Synopsys DOT com
    My BLOG http://geekswithblogs.net/bruceeitman
    I work for
    Synopsys

    Friday, July 13, 2018 6:42 PM