Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gmtime

Status
Not open for further replies.

MayFlowerNew

Programmer
Dec 21, 2004
20
CH
Hi,

is there any way to calculate other date&time like london, tokyo from gmtime?

Thanks in advance
 
yeah simple if you know the time difference just add it to the hour member of the struct.

i.e. gmt to cet
Code:
#include <stdio.h>
#include <time.h>
#define CET (1)
int main ()
{
  time_t rawtime;
  tm * ptm;
  time ( &rawtime );
  ptm = gmtime ( &rawtime );
  printf ("CET now is :-%2d:%02d\n", ptm->tm_hour+CET, ptm->tm_min);
  return 0;
}
or very similar.
 
Hi CodingNovice,
Thanks for the reply but say I am looking for date, time of tokyo. The timeoffset is 9 hours. if I add directly to the hour field it gives figure which is greater than 24 and naturally this dose not change the date field.

I am looking for something where we add the offset and it gives the new tm structure.

Thanks again
 
Instead of modifying the tm struct, just modify the time_t by adding the time offset x 3600.
 
Yes this sounds a good idea, let me try and get back to you..

Thanks a lot
 
Im sure localtime can do it as well but I dont know anything about C locales.
 
Note that in some time zones like India, the offsets are on the half hour. eg Mumbai (Bombay) is 5.5 hours ahead of GMT.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top