UNIXTime->SYSTEMTIME

I want a function that reads a SYSTEMTIME structure and returns an integer describing the time in UNIX format , and vice-verca
Thanks
LVL 6
WxWAsked:
Who is Participating?
 
mikeblasConnect With a Mentor Commented:

You need these headers:

#include <winbase.h>
#include <winnt.h>
#include <time.h>

This code will get you a FILETIME:

void UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
  // Note that LONGLONG is a 64-bit value
  LONGLONG ll;

  ll = Int32x32To64(t, 10000000) + 116444736000000000;
  pft->dwLowDateTime = (DWORD)ll;
  pft->dwHighDateTime = ll >> 32;
}

Given a time_T, you can get to a SYSTEMTIME with this code as well as the above function:

void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst)
{
  FILETIME ft;

  UnixTimeToFileTime(t, &ft);
  FileTimeToSystemTime(&ft, pst);
}

See KB article Q167296 for more information.

B ekiM

0
 
mikeblasCommented:
Which Unix time format do you want to start with, specifically?  time_t?  struct tm?  Something else?  What?

B ekiM


0
 
WxWAuthor Commented:
Not a structure
I mean UNIX-Time integer , i.e. starting from 1st January 1970

0
 
WxWAuthor Commented:
Thanks mikeblas , and sorry for the delay , I was never informed from EE for your answer =)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.