Thread: playin with the time struct

  1. #1
    Registered User
    Join Date
    Apr 2019
    Posts
    662

    playin with the time struct

    i have this silly code just to see what i get from each struct member
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    int main()
    {
        time_t mytime;
        struct tm *tmp;
    
        mytime = time(NULL);
        printf("local time is %s", ctime(&mytime));
    
        if (!(tmp = gmtime(&mytime)))
        {
            printf("UTC time not available\n");
        }
        else
        {
            printf("UTC time is %s", asctime(tmp));
            printf("%ld\n", tmp->tm_gmtoff);
            printf("hour is %d\n", tmp->tm_hour);
            printf("daylight savings is %d\n", tmp->tm_isdst);
            printf("day of the month is %d\n", tmp->tm_mday);
            printf("minuetes past the hour is %d\n", tmp->tm_min);
            printf("month is %d\n", tmp->tm_mon + 1);
            printf("seconds = %d\n", tmp->tm_sec);
            printf("day of the week is %d\n", tmp->tm_wday);
            printf("day of the year is %d\n", tmp->tm_yday);
            printf("year is %d\n", tmp->tm_year + 1900);
            printf("time zone is %s", tmp->tm_zone);
        }
        return 0;
    }
    in general i get what i expected. however daylight saving is 0 which is correct for the answers i get however how do i make it take daylight savings time into account? or is that down to the os?
    The other question is what is the tm_gmtoff i just get a value 0.
    coop

  2. #2
    Registered User catacombs's Avatar
    Join Date
    May 2019
    Location
    /home/
    Posts
    72
    From a Stack Overflow answer:

    tm_isdst A flag that indicates whether daylight saving time is in effect at the time described. The value is positive if daylight saving time is in effect, zero if it is not, and negative if the information is not available.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. time struct
    By bazzano in forum C Programming
    Replies: 3
    Last Post: 05-25-2007, 12:23 AM
  2. struct and run-time error
    By jamez05 in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2006, 12:03 PM
  3. vector - struct - one last time
    By FoodDude in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2005, 07:20 PM
  4. time precision (ctime), tm struct question
    By cjschw in forum C++ Programming
    Replies: 1
    Last Post: 12-26-2003, 01:51 PM
  5. struct tm* time OVER HEAD question
    By cjschw in forum C++ Programming
    Replies: 2
    Last Post: 09-27-2003, 01:17 AM

Tags for this Thread