The Time.h function in C language

Source: Internet
Author: User

Mainly used to obtain the display system time and timing, only to discuss the acquisition system time;

First on the code:

1#include"stdio.h"2#include"time.h"3 4 intMainvoid)5 {6     structTM *Local;7 time_t t;8t=Time (NULL);9Local=localtime (&t);Ten     //Local=gmtime (&t); Oneprintf"%d.%d\n", local->tm_year+1900, local->tm_mon+1); A     return 0; -}

Explain:

Use the time function to return a calendar period from January 1, 1970 0:0 0 seconds to the current number of seconds;

Use the LocalTime function to convert the calendar time to a TM structure to store it,

struct Definition I:

1 structTM2 {3     intTm_sec;/*seconds:0-59 (K&r says 0-61?)*/4     intTm_min;/*minutes:0-59*/5     intTm_hour;/*Hours since midnight:0-23*/6     intTm_mday;/*Day of the month:1-31*/7     intTm_mon;/*Months *since* january:0-11*/8     intTm_year;/*years since 1900*/9     intTm_wday;/*Days since Sunday (0-6)*/Ten     intTm_yday;/*Days since Jan 1:0-365*/ One     intTM_ISDST;/*+1 Daylight Savings time, 0 No DST, A *-1 don ' t know*/ -};

Call the corresponding member to display the system time;

The Time.h function in C language

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.