Return to Snippet

Revision: 30398
at August 13, 2010 05:49 by oznek


Initial Code
#include<time.h>
#include<stdio.h>
#include <stdlib.h>
#include <string.h>

/*
  can be called in shell with:

  shell$ TZ="Europe/Rome" ./teste

 */

int main(int argc, char *argv[])
{
    time_t now_time;
    struct tm *now;
    
    // Forcing timezone

    //setenv("TZ", "Europe/Rome", 1);
    //tzset();
    
    time(&now_time);
    printf("Now (unix timestamp): %ld \n\n", now_time);

    now = localtime(&now_time);

    printf(">>>> Now (gmt offset %ld): %s\n", now->tm_gmtoff, asctime(now));
    printf(">>>> isDst: %d\n", now->tm_isdst);
    printf(">>>> tzname: %s\n", now->tm_zone);


    return 0;
}

Initial URL


Initial Description


Initial Title
Timezone information in C (offset, names, etc)

Initial Tags


Initial Language
C