Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 614
  • Last Modified:

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
0
WxW
Asked:
WxW
  • 2
  • 2
1 Solution
 
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
 
mikeblasCommented:

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
 
WxWAuthor Commented:
Thanks mikeblas , and sorry for the delay , I was never informed from EE for your answer =)
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now