C Programming/C Reference/time.h/asctime

From Wikibooks, open books for an open world
Jump to: navigation, search

Template:Db-nocontext

Name[edit]

asctime(), asctime_r(),

Introduction[edit]

In C language function asctime() is included in library function time.h. This function translate time structure into an ASCII string. It will display in the form as Day Month Date Time Year\n\0. e.g. Sun Sep 5 10:56:01 2011\n\0. This function converts the broken-down time value into a string having same format as ctime(). The function asctime_r() does the same thing but it stores the string in user-supplied buffer having memory of at least 26 bytes.

Description[edit]

In C programming, functions asctime(), asctime_r() are used. We can obtain time by calling the functions gmtime(), gmtime64(), localtime(). The asctime() function uses 24 hour clock. The days are given as: mon, tue, wed, thu, fri, sat, sun and months as: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec. the new line character(\n) and blank spaces(/0) occupy last two positions of the string. The result produce by the string contains exactly 26 characters. asctime() always save this string to the same location. on every call to this function the old string gets overwrite. Time of this function starts from universal time that is 00:00:00 and date starts from january 1 1970.


See also[edit]

asctime_r(), clock(), ctime(), gmtime().


Template:Linux man pages