Download presentation
Presentation is loading. Please wait.
Published byDontae Grill Modified over 10 years ago
1
Unix Time Functions CNS 3210
2
The basic Linux (and Unix) time service counts the number of seconds that have passed since January 1, 1970 (UTC). These seconds are normally stored in a variable whose type is time_t. This is called calendar time.
3
We can get calendar time by using the call time_t time (time_t *tptr); returns the time, and stores the value here if the argument is non-null.
4
time_t struct tm string formatted string kernel time calendar time broken down time gmtime localtime mktime ctime asctime strftime takes time zone into account
5
struct tm { int tm_sec;// seconds after the minute [0-61] int tm_min;// minutes after the hour [0-59] int tm_hour;// hours after midnight [0-23] int tm_mday;// day of the month [1-31] int tm_mon;// month of the year [0-11] int tm_year;// years since 1900 int tm_wday;// day of the week [0-6] int tm_yday;// days since Jan 1 [0-365] int tm_isdst// daylight savings flag [pos, 0, neg] }; allows leap seconds dststtnot avail
6
time_t to tm #include struct tm *gmtime (const time_t *tptr); struct tm *localtime (const time_t *tptr); broken down time is in local time, given time zone and daylight savings broken down time is in UTC
7
tm to time_t time_t mktime (struct tm *tptr);
8
generating time strings char *asctime (const struct tm *tmptr); char (ctime (const time_t *tptr); both generate a 26 character string of the form Tue Sep 26 16:49:05 2002\n\0
9
Generating a formatted string size_t strftime (char *tbuf, size_t maxsize, const char *format, const struct tm *tptr); returns the size of the formatted string if successful 0 if fails a broken down time the buffer to store the string in, and its max size the format string – works like printf
10
FormatDescriptionExample %aabbreviated weekday nameTue %Afull weekday nameTuesday %babbreviated month nameJan %Bfull weekday nameJanuary %cdate and timeTue Jan 14 19:40:05 2002 %dday of the month [00-31]14 %Hhour of 24 hour day [00-23]19 %Ihour of 24 hour day [00-12]07 %jday of the year [001-366]014 %mmonth [01-12]01 %Mminute [00-59]40 %pam or pmPM %Ssecond [00-61]05 %USunday week number [00-53]02 %wweekday [0=Sunday – 6]5 %WMonday week number [00-53]07 %xdate01/14/02 %Xtime19:40:04 %yyear without century [00-99]02 %Yyear with century2002 %Ztime zone nameMST
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.