Time function and use examples in C language

xiaoxiao2021-03-06  100

#include / * null * / # include / * ctime, asctime * /

Main () {Time_t now; / * define 'now'. Time_t is probably * a typedef * /

/ * Calender Time Is The Number of * Seconds Since 1/1/1970 * /

Now = Time ((Time_t *) null); / * get the system time and put it * inTo 'now' as 'caleder time' * /

Printf ("% s", ctime (& now)); / * Format Data IN 'now' * Note That 'ctime' Inserts a * '/ n' * /

/ ************************************************** ******************* /

/ * Here is Another Way To Extract the Time / Date Information * /

Time (& NOW);

Printf ("% s", ctime (& now)); / * Format Data in 'now' * /

/ ************************************************** ******************* /

{Struct tm * l_time; l_time = localtime (& now); / * Convert 'calender time' to * 'local time' - return a pointer * to the 'tm' structure localtime * reserves the storage for us * / printf (.. "% s", asctime (l_time));

/ ************************************************** ******************* /

Time (& NOW); Printf ("% s", asctime (localtime (& now));

/ ************************************************** ******************* /

{Struct tm * l_time; char string [20]; time (& now); l_time = localtime (& now); struntime (string, sizeof string, "% D-% B-% Y / N", L_TIME); Printf (" % S ", String);}}

转载请注明原文地址:https://www.9cbs.com/read-95925.html

New Post(0)