Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I am searching for a ready made function which return time,
input will be time, Target time zone (for ex: EDT), flag to consider day light saving or not.

Input and result time can be in any format like CTime, SYSTEMTIME, etc.

Thanks.
Posted
Comments
fjdiewornncalwe 25-Nov-10 13:59pm    
What have you tried to do? What is the problem you encountered.

You just need to set your time value into a struct tm
and use the localtime()[^] function. See also the Time Management[^] routines.
 
Share this answer
 
Don't use localtime. It does not work properly, especially if you are using time zones outside the US. You might try BOOST.
 
Share this answer
 
This is what I think you are asking for:

INPUT 1: time in UTC ("Greenwich" time)
INPUT 2: time zone string (3 characters)
INPUT 3: bool to say whether DST is to be considered
OUTPUT: local time in that time zone at that time

This is a difficult problem. First you would have to restrict the range of input times. It would be hard to say whether DST was/will be in effect for dates a long time in the past or dates in the future.

There is no way using standard C/C++ functions to get this information. I don't even think you would be able to ask Windows if a certain day in the past used DST. (DST start and end times often vary from year to year). And if you can I wouldn't trust the answer.

I think you would have to research this yourself to build up a table of when DST started and ended for all the time zones you are interested in for the range of dates you want. You also need a table to convert the 3 character time zone codes to +/- hours from UTC time.

I doubt whether anyone has written a general function to do this, or even if all the information to do so has been gathered into the one place.

It may also be a problem that some input times can correspond to 2 different output times.
 
Share this answer
 
v2
Comments
Richard MacCutchan 10-Dec-10 9:24am    
Checkout my suggestions in Answer 2.

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



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