1 / 10

Unix Time Functions

Unix Time Functions. CNS 3210. 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. We can get calendar time by using the call.

alodie
Télécharger la présentation

Unix Time Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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. string formatted string asctime strftime struct tm broken down time ctime localtime gmtime mktime time_t calendar time time kernel takes time zone into account

  5. struct tm 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 dst stt not avail

  6. time_t to tm #include <time.h> struct tm *gmtime (const time_t *tptr); struct tm *localtime (const time_t *tptr); broken down time is in UTC broken down time is in local time, given time zone and daylight savings

  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); the buffer to store the string in, and its max size a broken down time the format string – works like printf returns the size of the formatted string if successful 0 if fails

  10. Format Description Example %a abbreviated weekday name Tue %A full weekday name Tuesday %b abbreviated month name Jan %B full weekday name January %c date and time Tue Jan 14 19:40:05 2002 %d day of the month [00-31] 14 %H hour of 24 hour day [00-23] 19 %I hour of 24 hour day [00-12] 07 %j day of the year [001-366] 014 %m month [01-12] 01 %M minute [00-59] 40 %p am or pm PM %S second [00-61] 05 %U Sunday week number [00-53] 02 %w weekday [0=Sunday – 6] 5 %W Monday week number [00-53] 07 %x date 01/14/02 %X time 19:40:04 %y year without century [00-99] 02 %Y year with century 2002 %Z time zone name MST

More Related