C Language Output system time

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.