How to Implement C language for obtaining system time in Linux

Source: Internet
Author: User
The C language implementation method for obtaining system time in Linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. How to Implement C language for obtaining system time in Linux
# Include // Header file in C Language
# Include // C language I/O

Void main ()
{
Time_t now; // instantiate the time_t Structure
Struct tm * timenow; // instantiate the tm structure pointer
Time (& now );
// The time function reads the current time (International Standard time is not Beijing time), and then transmits the value to now

Timenow = localtime (& now );
// The localtime function converts the time now obtained from time to the time in your computer (that is, the region you set)

Printf ("Local time is % s \ n", asctime (timenow ));
// In the previous sentence, the asctime function converts the time into characters and outputs the time using the printf () function.
}

Note: time_t is a struct defined in time. h. The prototype of the tm struct is as follows:

Struct tm
{
Int tm_sec; // seconds 0-61
Int tm_min; // minutes 1-59
Int tm_hour; // hours 0-23
Int tm_mday; // day of the month 1-31
Int tm_mon; // months since jan 0-11
Int tm_year; // years from 1900
Int tm_wday; // days since Sunday, 0-6
Int tm_yday; // days since Jan 1, 0-365
Int tm_isdst; // Daylight Saving time indicator
};
Related Article

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.