C ++ System Time Acquisition

Source: Internet
Author: User
Tags time and date

Functions can be used to obtain the current system in C ++.

Time_t time (time_t * timer );

If this function is used, if the input parameter is not null, it will set the current system time to this pointer.

The number returned by this function is from hours, Jan 1, 1970 UTC seconds.

struct tm * localtime (const time_t * timer);
Convert time_t type to local time

char* asctime (const struct tm * timeptr);
Format the local time into a string.
Example:
/* localtime example */#include <stdio.h>      /* puts, printf */#include <time.h>       /* time_t, struct tm, time, localtime */int main (){  time_t rawtime;  struct tm * timeinfo;  time (&rawtime);  timeinfo = localtime (&rawtime);  printf ("Current local time and date: %s", asctime(timeinfo));  return 0;}
Output:
Current local time and date: Wed Feb 13 17:17:11 2013
Of course, we can process the data in the structure of TM to obtain the output time in the desired format.

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.