First, the output system time
#include <stdio.h> #include <time.h> #include <stdlib.h>typedef struct TM timeinfo;//time structure int main () {time_t rawtime;//Time type timeinfo *timeinfos;//Temporal structure pointer variable time (&rawtime); The number of seconds to get the time, starting January 1, 1970, deposited Rawtimetimeinfos = LocalTime (&rawtime); Convert the number of seconds to local time printf ("Current time is:%s\n", Asctime (Timeinfos)); Convert to ASCII format output printf ("%d%d months%d days%d"%d seconds ", timeinfos->tm_year+1900, //year starting from 1900, to add 1900timeinfos->tm_ Mon+1, //month starting from 0, to add 1timeinfos->tm_mday,timeinfos->tm_hour,timeinfos->tm_min,timeinfos->tm_sec) ;//Switch to Chinese output retur 0;}
second, timing output system time
#include <stdio.h> #include <time.h> #include <stdlib.h> #include <windows.h>typedef struct TM timeinfo;//time structure void Printtime () {time_t rawtime;//Time type timeinfo *timeinfos;//time structure pointer variable times (&rawtime); The number of seconds to get the time, starting January 1, 1970, deposited Rawtimetimeinfos = LocalTime (&rawtime); Convert the number of seconds to local time printf ("Current ASCII time is:%s\n", Asctime (Timeinfos)); Convert to ASCII format output printf (%d%d months%d timeinfos->tm_year+1900%d of%d seconds \ n),, //year starting from 1900, to add 1900timeinfos->tm _mon+1, //month is starting from 0, to add 1timeinfos->tm_mday,timeinfos->tm_hour,timeinfos->tm_min,timeinfos->tm_sec );//Switch to Chinese output} int main () {while (1) {printtime (); Sleep (1000);} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C Language Output system time