C ++ get the calendar time

Source: Internet
Author: User

Get calendar time

We can use the time () function to obtain the calendar time. Its prototype is:
Time_t time (time_t * timer );

If you have already declared the timer parameter, you can return the current calendar time from the timer parameter, or return the current calendar time from a time point (for example: january 1, 1970 00:00:00) the number of seconds until now. If the parameter is null (NUL), the function returns the current calendar time only by returning the value. For example, the following example shows the current calendar time:

# Include "time. H"
# Include "stdio. H"
Int main (void)
{
Struct TM * PTR;
Time_t lt;
Lt = Time (NUL );
Printf ("the calendar time now is % d \ n", LT );
Return 0;
}

The running result is related to the current time. The running result is:

The calendar time now is 1122707619

1122707619 is the calendar time when I run the program. That is, the number of seconds from January 1, 1970 00:00:00 to this time point.

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.