"C + +" gets the current system time

Source: Internet
Author: User

1#include <iostream>2#include <Ctime>3 using namespacestd;4 5 intMain ()6 {7 time_t t;8Time (&t); 9cout<<"Now is :"<<ctime (&t) <<Endl;Ten     return 0; One}

"NOTE"

The following definitions are available for time_t,<time.h>:

------------------------------------------------------------------------------
#ifndef _time_t_defined
typedef long time_t; /* Time value */
#define _TIME_T_DEFINED/* Avoid multiple def ' s of time_t */
#endif

------------------------------------------------------------------------------

In other words, the time_t type is actually a long int type.

Time function Prototype:

time_t Time (time_t * timer);

The return value is the same as the value of the timer, which represents the number of seconds between 0:0 and 0 seconds from January 1, 1970, in fact a long int from 32-bit lengths can only be represented to January 18, 2038 19:14 07 seconds.

CTime function Prototypes:

Char *ctime (const time_t *timer);

//Convert the timer to a more intuitive time representation [day of the week: minutes: seconds ], and returned as a string.

"C + +" gets the current 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.