Solved

UNIXTime->SYSTEMTIME

Posted on 1998-11-20
4
600 Views
Last Modified: 2013-12-03
I want a function that reads a SYSTEMTIME structure and returns an integer describing the time in UNIX format , and vice-verca
Thanks
0
Comment
Question by:WxW
  • 2
  • 2
4 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1416221
Which Unix time format do you want to start with, specifically?  time_t?  struct tm?  Something else?  What?

B ekiM


0
 
LVL 6

Author Comment

by:WxW
ID: 1416222
Not a structure
I mean UNIX-Time integer , i.e. starting from 1st January 1970

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 40 total points
ID: 1416223

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
 
LVL 6

Author Comment

by:WxW
ID: 1416224
Thanks mikeblas , and sorry for the delay , I was never informed from EE for your answer =)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question