Why not subtract the difference in hours between GMT and New York from the hour in GMT, adjusting for MN when necessary? I believe hour is one of the members of the tm struct.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
what operating system? There are no standard C or C++ functions to do that. If you are using MS-Windows you can call the win32 api function GetTimeZoneInformation ()
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
EST is GMT - 5. So if you know what time zone your program is running in then adjust accordingly. use gmtime() then subtract 5 hours for eastern.
Ancient Dragon
Retired & Loving It
30,040 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,341
Beaten to the punch, but I might have said something like this...
#include <stdio.h>
#include <time.h>
int main (void)
{
time_t t = time(0);
if ( t != (time_t)-1 )
{
struct tm* data = gmtime(&t);
if ( data )
{
data->tm_hour -= 5 + data->tm_isdst;
t = mktime(data);
if ( t != (time_t)-1 )
{
char buffer[32];
if ( strftime(buffer, sizeof buffer, "%X", data) )
{
printf("NY time = %s\n", buffer);
}
}
}
}
return 0;
}
/* my output
NY time = 00:36:52
*/
Of course, I don't know whether or not gmtime will give you the correct Daylight Savings Time for New York. But it's a start.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
First I'd convert GMT to EST. Then I'd see if the EST date falls withing the interval that DST starts and ends. If so, then I'd add an hour to EST time to convert from not DST to DST. Or something like that. You may need to fine tune it to the hour that DST starts in addition to the date that DST starts, but I think you get the picture.
Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
Isn't the question somewhat of the reverse? That is, if I am in South Africa and I have my program running, how can it tell me with correct reference to DST what the time is in New York? OP: Correct me if I am leading this astray.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
I am using cygwin,
Quoted from the Cywin website:
"Windows ports of many of the popular GNU software tools, including the BASH and tcsh shells."
So WHY in the world do you need cygwin when you are using Linux? It simply makes no sense to emulate tools you already have at your disposal.I tried to find /etc/profile in linux but of no use. Is there a simple way to do this? :rolleyes: I think the /etc/profile file is for compiler optimization - the ~/.profile file is the usually the one that contains timezone information, which is in /etc/timezone as previously stated.
John A
Vampirical Lurker
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339