time(); function Function prototype: time_t time(time_t *timer) /* time - Get the current calendar time of the computer system * Functions that process date and time are calculated based on the return value of this function* * Function prototype: * #include <time.h> * * time_t time(time_t *calptr); * * Return value: * Success: Number of seconds since 1970-1-1, 00:00:00 * * use: * time_t now; * * time(&now); // == now = time(NULL); */ localtime(); function Function prototype: struct tm *localtime(const time_t *timer) /* * localtime - converts a time value to local time, taking into account the local time zone and daylight saving time flags* * Function declaration: * #include <time.h> * * struct tm * localtime(const time_t *timer); * */ //The definition of structure tm is: struct tm { int tm_sec; /* Seconds: 0-59 (K&R says 0-61?) */ int tm_min; /* Minutes: 0-59 */ int tm_hour; /* Hours since midnight: 0-23 */ int tm_mday; /* Day of the month: 1-31 */ int tm_mon; /* Months *since* january: 0-11 */ int tm_year; /* Years since 1900 */ int tm_wday; /* Days since Sunday (0-6) */ int tm_yday; /* Days since Jan. 1: 0-365 */ int tm_isdst; /* +1 Daylight Savings Time, 0 No DST, * -1 don't know */ }; Since time_t is actually a long integer, what should we do if the number of seconds from a time point (usually 00:00:00 on January 1, 1970) to that time (i.e. calendar time) exceeds the range of numbers that can be represented by a long integer? For the value of the time_t data type, the time it represents cannot be later than 19:14:07 on January 18, 2038. In order to represent longer time, some compiler manufacturers introduced 64-bit or even longer integers to save calendar time. For example, Microsoft uses the __time64_t data type to save calendar time in Visual C++, and obtains calendar time through the _time64() function (instead of using the 32-bit word time() function). In this way, the data type can be used to save the time before 00:00:00 on January 1, 3001 (excluding this time point). /* * time(); * @author 李政<[email protected]> */ #include <time.h> #include <stdio.h> int main(int argc, char* argv[]) { struct tm *tp; time_t t = time(NULL); tp = localtime(&t); printf("%d/%d/%d\n",tp->tm_mon+1,tp->tm_mday,tp->tm_year+1900); printf("%d:%d:%d\n",tp->tm_hour,tp->tm_min,tp->tm_sec); return 0; } The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: JavaScript mobile H5 image generation solution explanation
>>: Solution to ERROR 1054 (42S22) when changing password in MySQL 5.7
This article shares the specific code of jQuery t...
Table of contents 1. Basic conditions for databas...
This article shares with you how to use the Vue s...
Recently, after refreshing the website, 503 Servi...
This article shares the specific code for the WeC...
CSS is the realm of style, layout, and presentati...
<br />I'm basically going crazy with thi...
Table of contents 1. Modify the my.cnf file of se...
Before hiding: After hiding: CSS: Copy code The co...
Install memcached yum install -y memcached #Start...
An optimization solution when a single MYSQL serv...
Process structure diagram Nginx is a multi-proces...
Table of contents 1. Introduction to binlog 2. Bi...
Table of contents 1. Multiple .catch 2. Multiple ...