| | |
Help to get time zone between GMT & new york
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2006
Posts: 19
Reputation:
Solved Threads: 0
Please can anyone help me to get the time zone between GMT & New York including the daylight saving.
I am able to get the timezone between GMT & localtime including the daylight saving. My program goes like this
But I am not able to New York local time. Thanks a lot in advance.
I am able to get the timezone between GMT & localtime including the daylight saving. My program goes like this
c Syntax (Toggle Plain Text)
time_t t = time(0); struct tm* data; data = localtime(&t); data->tm_isdst = 0; time_t a = mktime(data); data = gmtime(&t); data->tm_isdst = 0; time_t b = mktime(data); int gmtoffset = (a - b)/3600;
But I am not able to New York local time. Thanks a lot in advance.
Last edited by ~s.o.s~; Dec 15th, 2006 at 12:53 pm. Reason: Added code tags learn to use them yourself.
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()
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Dec 2006
Posts: 19
Reputation:
Solved Threads: 0
I am using Linux operating system. so I dont think I can call the win32 api function GetTimeZoneInformation().
Is there a possibility to get current time in new york each time the program runs, so that i can calculate the timezone??
Is there a possibility to get current time in new york each time the program runs, so that i can calculate the timezone??
Beaten to the punch, but I might have said something like this...
Of course, I don't know whether or not
C Syntax (Toggle Plain Text)
#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 */
gmtime will give you the correct Daylight Savings Time for New York. But it's a start. Last edited by Dave Sinkula; Dec 15th, 2006 at 1:34 am. Reason: Updated time and added disclaimer.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Dec 2006
Posts: 19
Reputation:
Solved Threads: 0
Thanxs a lot for your reply. I understand. Right now I am using the same idea what you have explained in my program.
But what I want to make is automatically generate the timezone as the EST changes to EDT (daylight saving). I dont want to go to the program each time when EST changes to EDT to change the variable from -5 to -4. Hope I have made it clear.
But what I want to make is automatically generate the timezone as the EST changes to EDT (daylight saving). I dont want to go to the program each time when EST changes to EDT to change the variable from -5 to -4. Hope I have made it clear.
•
•
Join Date: Jul 2005
Posts: 1,699
Reputation:
Solved Threads: 271
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.
•
•
Join Date: May 2004
Posts: 178
Reputation:
Solved Threads: 10
UNIX only:
will return the timezone setting. The result is in the form
xxxNxxx, example MST7MDT. TZ has to be set for localtime() to return the correct time. MST is GMT +7. If TZ is not set the system is running GMT by default. Assuming time has been set.....
NY is EST5EDT. It's GMT+5.
C Syntax (Toggle Plain Text)
getenv("TZ");
will return the timezone setting. The result is in the form
xxxNxxx, example MST7MDT. TZ has to be set for localtime() to return the correct time. MST is GMT +7. If TZ is not set the system is running GMT by default. Assuming time has been set.....
NY is EST5EDT. It's GMT+5.
![]() |
Similar Threads
- Chess Tournament (Geeks' Lounge)
- New Time Format (DaniWeb Community Feedback)
- Time zone problem (PHP)
- Looking for Web Developers (Web Development Job Offers)
- my PC time is off 20 minutes, have correct time zone? (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: reading a file using fscanf
- Next Thread: Loop validation in C - enlightenment needed
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks binarysearch calculate changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic execv feet fflush fgets file fork forloop framework function getlasterror givemetehcodez grade gtkwinlinux hacking histogram inches include incrementoperators input intmain() iso kernel keyboard km license linked linkedlist linux list lists locate logical_drives looping loopinsideloop. lowest matrix microsoft motherboard mqqueue number oddnumber odf opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scanf scripting segmentationfault sequential socket socketprograming standard string structures systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






