/sys$common/syshlp/HELPLIB.HLB  —  DECdts  utc_gmtzone, Example
    The following example prints out the current time in both local
    time and GMT time.

    utc_t       now;
    struct tm   tmlocal, tmgmt;
    long        tzoffset;
    int         tzdaylight;
    char        tzlocal[80], tzgmt[80];

    /*
     *   Get the current time once, so both conversions use the same
     *   time...
     */

    utc_gettime(&now);

    /*
     *   Convert to local time, using the process TZ environment
     *   variable...
     */

    utc_localtime(&tmlocal,       /* Out: Local time tm structure  */
                  (long *)0,      /* Out: Nanosec of time          */
                  (struct tm *)0, /* Out: Inaccuracy tm structure  */
                  (long *)0,      /* Out: Nanosec of inaccuracy    */
                  &now);          /* In:  Current binary timestamp */

    /*
     *   Get the local time zone name, offset from GMT, and current
     *   daylight savings flag...
     */

    utc_localzone(tzlocal,     /* Out: Local time zone name          */
                  80,          /* In:  Length of loc time zone name  */
                  &tzoffset,   /* Out: Loc time zone offset in secs  */
                  &tzdaylight, /* Out: Local time zone daylight flag */
                  &now);       /* In:  Current binary timestamp      */

    /*
     *   Convert to GMT...
     */

    utc_gmtime(&tmgmt,         /* Out: GMT tm structure              */
               (long *)0,      /* Out: Nanoseconds of time           */
               (struct tm *)0, /* Out: Inaccuracy tm structure       */
               (long *)0,      /* Out: Nanoseconds of inaccuracy     */
               &now);          /* In:  Current binary timestamp      */

    /*
     *   Get the GMT time zone name...
     */

    utc_gmtzone(tzgmt,         /* Out: GMT time zone name            */
                80,            /* In:  Size of GMT time zone name    */
                (long *)0,     /* Out: GMT time zone offset in secs  */
                (int *)0,      /* Out: GMT time zone daylight flag   */
                &now);         /* In:  Current binary timestamp      */

    /*
     *   Print out times and time zone information in the following
     *   format:
     *
     *          12:00:37 (EDT) = 16:00:37 (GMT)
     *          EDT is -240 minutes ahead of Greenwich Mean Time.
     *          Daylight savings time is in effect.
     */

    printf("%d:%02d:%02d (%s) = %d:%02d:%02d (%s)\n",
           tmlocal.tm_hour, tmlocal.tm_min, tmlocal.tm_sec, tzlocal,
           tmgmt.tm_hour, tmgmt.tm_min, tmgmt.tm_sec, tzgmt);
    printf("%s is %d minutes ahead of Greenwich Mean Time\n",
           tzlocal, tzoffset/60);
    if (tzdaylight != 0)
        printf("Daylight savings time is in effect\n");
Close Help