In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use time (NULL) function and localtime () to get the current time under linux. It is very detailed and has certain reference value. Friends who are interested must finish reading it.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
Time (); function
Function prototype: time_t time (time_t * timer)
Function purpose: get the calendar time of the machine or set the calendar time
Headline: time.h
Input parameter: timer=NULL, get the machine calendar time, = time value is used to set the calendar time
Time_t is a long type
/ * time-get the current calendar time (Calender Time) of the computer system * all functions dealing with date and time are based on the return value of this function * * function prototype: * # include * * time_t time (time_t * calptr); * * return value: * success: number of seconds, from 1970-1-1 to 1-1. * * time (& now); / / = now = time (NULL); * /
Localtime (); function
Function prototype: struct tm * localtime (const time_t * timer)
Function purpose: returns a machine time information expressed in tm structure
Headline: time.h
Input parameter: timer: machine time obtained using the time () function
/ * * localtime-converts the time value into local time, taking into account the local time zone and daylight saving time flag * * function declaration: * # include * * struct tm * localtime (const time_t * timer); * * / / the structural tm is defined as: struct tm {int tm_sec; / * Seconds: 0-59 (Knowr 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: 0365 * / int tm_isdst; / * + 1 Daylight Savings Time, 0 No DST, *-1 don't know * /}
Since time_t is actually a long integer, what if the number of seconds (that is, calendar time) from a point in time (usually 00:00:00 on January 1, 1970) to that point (that is, calendar time) exceeds the number of long shaping can represent? For a value of the time_t data type, it represents a time no later than 19:14:07 on January 18, 2038. In order to represent a longer period of time, some compiler vendors have introduced 64-bit or more shaping numbers to save calendar time. For example, Microsoft uses the _ _ time64_t data type in Visual C++ to save the calendar time, and uses the _ time64 () function to obtain the calendar time (instead of using the 32-bit word time () function), so that it can save the time before 00:00:00 on January 1, 3001 (excluding this point in time).
/ * * time (); * @ author Li Zheng * / # include # include 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;} these are all the contents of the article "how to use the time (NULL) function and localtime () to get the current time under linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.