In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the C language strftime () how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will gain after reading this C language strftime () how to use the article, let's take a look.
The strftime function is mainly used for time formatting, and its function prototype is as follows:
Size_t _ cdecl strftime (char * _ restrict__ _ Buf,size_t _ SizeInBytes,const char * _ restrict__ _ Format,const struct tm * _ restrict__ _ Tm)
It has four parameters:
_ Buf, indicating the returned time string
_ SizeInBytes, the maximum number of bytes to write
_ Format, which is a C string that contains any combination of normal characters and special format specifiers.
_ Tm, enter the time structure
The C string formatter is described as follows:
Replace the specifier with example an abbreviated day name Sun%A full day of the week name Sunday%b abbreviated month name Mar%B full month name March%c date and time representation Sun Jan 23 02:56:02 2022% d day of month (01-31) 19%H24 hour format (00-23) 14%I12 hour format (01-12) 05% j The week ordinal of the month (01-12) 08% M minutes (00-59) 55%pAM or PM name PM%S seconds (00-61) 02% U in decimal number The day of the week expressed as the first Sunday as the first day of the first week (00-53) 33% w decimal number, the Sunday as 0 (0-6) 4% W the week ordinal of the year, and the first Monday as the first day of the first week (00-53) 34% x date denotes the 08ram 1912% X time representation 02VuV50RV 06% y year. The last two digits (00-99) 01% Y year 2012% Z time zone name or abbreviation CDT%% a% sign%
The time structure is in the following format:
Struct tm {int tm_sec; / * seconds, ranging from 0 to 59 * / int tm_min; / * minutes, from 0 to 59 * / int tm_hour; / * hours, from 0 to 23 * / int tm_mday / * days of the month, from 1 to 31 * / int tm_mon; / * months, from 0 to 11 * / int tm_year; / * years from 1900 * / int tm_wday; / * days of the week, from 0 to 6 * / int tm_yday / * the day of the year, ranging from 0 to 365 * / int tm_isdst; / * daylight saving time * /}
In other words, the function of the strftime function is to convert the time structure to the specified string format. Here is a simple example to demonstrate the use of the strftime function.
# include # include # include int main (int argc, char** argv) {time_t now_time; struct tm * info; char buffer [80]; time (& now_time); info = localtime (& now_time); strftime (buffer, 80, "% Y-%m-%d% H:%M:%S", info) Printf ("date and time formatted:% s\ n", buffer); return 0;}
First, use the time function to get the current time, and then use the strftime function to print the time in the specified string format. The printed result is as follows:
From the printed results, we can see that the format of the printed string is the same as that specified in the function, so that by setting the format of the string, you can print out the string of time and date according to your own requirements, which is more flexible and convenient to use.
This is the end of the article on "how to use strftime () in C language". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to use strftime () in C language". If you want to learn more knowledge, you are 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.