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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C function displaying the timezone 1

Status
Not open for further replies.

carrick1

Programmer
Sep 15, 2005
2
0
0
GB
Hi
I am looking at some code that uses ctime() to convert and display a UTC epoch time to an asci timestamp in the format

"Wed Jun 30 21:49:08 1993\n"

The output does not display the timezone. Is there a function I can use that does the same but will output something like:

"Wed Jun 30 21:49:08 GMT 1993\n"

 
If your compiler is POSIX compliant, calling any of the time functions should set the second argument of the gobal timezone array. This works on my Solaris 7 unix box:

Code:
#include <stdio.h>
#include <time.h>

int
main (void)
{
  char buf[256];
  struct tm *tmptr;
  time_t now;

  tzset ();
  now = time(NULL);
  tmptr = localtime (&now);

  printf ("Timezone is: %s\n", tzname[1]);
}

This prints "PDT" for me. If you want "GMT", I'd search the web. Probably somebody has written an offset.

 
Use strftime() to format the time text representation as you wish.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top