Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Possibly more of an OS question.. but here goes.

I'm creating backups based on the current time, using localtime to convert to the user date / time

time_t          rawtime;
     struct tm      *timeinfo;
     char            timestring [TIME_STRING_LENGTH+1];

     time (&rawtime);
     timeinfo = localtime (&rawtime);

     strftime (timestring,TIME_STRING_LENGTH,"%Y_%m_%d_%H_%M_%S",timeinfo);




MSDN -
C#
Convert a time value and correct for the local time zone


I've deployed this to a number of our test boxes - just one gets it wrong - I'm in the UK, it's BST today (GMT+1). One machine (Win7_64) appears to output GMT - one hour behind what's on the clock in the systray. Clock settings appear to be consistent across all my machines.

Is there another API I should be using?

Thanks

What I have tried:

gmtime, msdn, google ......................
Posted
Updated 23-Sep-16 1:02am
Comments
Richard MacCutchan 23-Sep-16 5:00am    
Just tried your code here (Woking) on Win 10 64 bit, and the values are all correct. Is there something odd about that system?
Simon Langdon 23-Sep-16 5:20am    
cheers - everyone here I've asked to run it says it works fine, Win10, Win8, Win7, Server 2012. Just one machine then }-(

1 solution

I've found a different function that seems to do what I expect :-)

SYSTEMTIME st;

GetLocalTime(&st);

CString time2;

time2.Format(TEXT ("%d_%d_%d_%d_%d_%d"), st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
 
Share this answer
 
Comments
Richard MacCutchan 23-Sep-16 7:41am    
That is still very weird.
Richard MacCutchan 23-Sep-16 7:45am    
Just checked again and both methods produce the same (correct) time.
Simon Langdon 26-Sep-16 5:24am    
Yes I discovered another machine on site that was also producing the wrong time - that was Win8 / 64. It doesn't seem OS specific. Someone suggested the bios clock, but that was consistent with Windows and other machines.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900