📄 stddate_details.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <meta name="generator" content="HTML Tidy for Linux/x86 (vers 1st October 2002), see www.w3.org"> <title>Standard C Date & Time</title> </head> <body bgcolor="#ffffff"> <table width="100%" bgcolor="#eeeeff"> <tr> <td><a href="index.html">cppreference.com</a> -> <a href="stddate.html">Standard C Time & Date</a> -> Details</td> </tr> </table> <h1>Standard C Date & Time</h1> <hr> <h2><a name="asctime">asctime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> char *asctime( const struct tm *ptr );</pre> </td> </tr> </table> <p>The function asctime() converts the time in the struct <i>ptr</i> to a character string of the following format:</p><pre> day month date hours:minutes:seconds year\n\0</pre> <p>An example:</p><pre> Mon Jun 26 12:03:53 2000</pre> <i>Related topics:</i><br> <strong><a href="#localtime">localtime()</a>, <a href="#gmtime">gmtime()</a>, <a href= "#time">time()</a>, and <a href="#ctime">ctime()</a>.</strong> <hr> <h2><a name="clock">clock</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> clock_t clock( void );</pre> </td> </tr> </table> <p>The clock() function returns the processor time since the program started, or -1 if that information is unavailable. To convert the return value to seconds, divide it by CLOCKS_PER_SEC. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SEC is always defined as 1000000.)</p> <i>Related topics:</i><br> <strong><a href="#time">time()</a>, <a href="#asctime">asctime()</a>, and <a href= "#ctime">ctime()</a>.</strong> <hr> <h2><a name="ctime">ctime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> char *ctime( const time_t *time );</pre> </td> </tr> </table> <p>The ctime() function converts the calendar time <i>time</i> to local time of the format:</p><pre> day month date hours:minutes:seconds year\n\0</pre> <p>using ctime() is equivalent to</p><pre> asctime( localtime( tp ) );</pre> <i>Related topics:</i><br> <strong><a href="#localtime">localtime()</a>, <a href="#gmtime">gmtime()</a>, <a href= "#time">time()</a>, and <a href="#asctime">asctime()</a>.</strong> <hr> <h2><a name="difftime">difftime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> double difftime( time_t time2, time_t time1 );</pre> </td> </tr> </table> <p>The function difftime() returns <i>time2</i>-<i>time1</i>, in seconds.</p> <i>Related topics:</i><br> <strong><a href="#localtime">localtime()</a>, <a href="#gmtime">gmtime()</a>, <a href= "#time">time()</a>, and <a href="#asctime">asctime()</a>.</strong> <hr> <h2><a name="gmtime">gmtime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> struct tm *gmtime( const time_t *time );</pre> </td> </tr> </table> <p>The gmtime() function returns the given <i>time</i> in Coordinated Universal Time (usually Greenwich mean time), unless it's not supported by the system, in which case NULL is returned. <a href= "static_return.html">Warning!</a></p> <i>Related topics:</i><br> <strong><a href="#localtime">localtime()</a>, <a href="#time">time()</a>, and <a href= "#asctime">asctime()</a>.</strong> <hr> <h2><a name="localtime">localtime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> struct tm *localtime( const time_t *time );</pre> </td> </tr> </table> <p>The function localtime() converts calendar time <i>time</i> into local time. <a href= "static_return.html">Warning!</a></p> <i>Related topics:</i><br> <strong><a href="#gmtime">gmtime()</a>, <a href="#time">time()</a>, and <a href= "#asctime">asctime()</a>.</strong> <hr> <h2><a name="mktime">mktime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> time_t mktime( struct tm *time );</pre> </td> </tr> </table> <p>The mktime() function converts the local time in <i>time</i> to calendar time, and returns it. If there is an error, -1 is returned.</p> <i>Related topics:</i><br> <strong><a href="#time">time()</a>, <a href="#gmtime">gmtime()</a>, <a href="#asctime">asctime()</a>, and <a href="#ctime">ctime()</a>.</strong> <hr> <h2><a name="strftime">strftime</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );</pre> </td> </tr> </table> <p>The function strftime() formats date and time information from <i>time</i> to a format specified by <i>fmt</i>, then stores the result in <i>str</i> (up to <i>maxsize</i> characters). Certain codes may be used in <i>fmt</i> to specify different types of time:</p> <table bgcolor="#eeeeff"> <tr> <td><strong>Code</strong></td> <td><strong>Meaning</strong></td> </tr> <tr> <td>%a</td> <td>abbreviated weekday name</td> </tr> <tr> <td>%A</td> <td>full weekday name</td> </tr> <tr> <td>%b</td> <td>abbreviated month name</td> </tr> <tr> <td>%B</td> <td>full month name</td> </tr> <tr> <td>%c</td> <td>the standard date and time string</td> </tr> <tr> <td>%d</td> <td>day of the month, as a number (1-31)</td> </tr> <tr> <td>%H</td> <td>hour, 24 hour format (0-23)</td> </tr> <tr> <td>%I</td> <td>hour, 12 hour format (1-12)</td> </tr> <tr> <td>%j</td> <td>day of the year, as a number (1-366)</td> </tr> <tr> <td>%m</td> <td>month as a number (1-12). <strong>Note:</strong> some versions of Microsoft Visual C++ may use values that range from 0-11.</td> </tr> <tr> <td>%M</td> <td>minute as a number (0-59)</td> </tr> <tr> <td>%p</td> <td>locale's equivalent of AM or PM</td> </tr> <tr> <td>%S</td> <td>second as a number (0-59)</td> </tr> <tr> <td>%U</td> <td>week of the year, sunday as the first day</td> </tr> <tr> <td>%w</td> <td>weekday as a decimal (0-6, sunday=0)</td> </tr> <tr> <td>%W</td> <td>week of the year, monday as the first day</td> </tr> <tr> <td>%x</td> <td>standard date string</td> </tr> <tr> <td>%X</td> <td>standard time string</td> </tr> <tr> <td>%y</td> <td>year in decimal, without the century (0-99)</td> </tr> <tr> <td>%Y</td> <td>year in decimal, with the century</td> </tr> <tr> <td>%Z</td> <td>time zone name</td> </tr> <tr> <td>%%</td> <td>a percent sign</td> </tr> </table> <p>The strftime() function returns the number of characters put into <i>str</i>, or zero if an error occurs.</p> <i>Related topics:</i><br> <strong><a href="#time">time()</a>, <a href="#localtime">localtime()</a>, and <a href= "#gmtime">gmtime()</a>.</strong> <hr> <h2><a name="time">time</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> #include <time.h> time_t time( time_t *time );</pre> </td> </tr> </table> <p>The function time() returns the current time, or -1 if there is an error. If the argument <i>time</i> is given, then the current time is stored in <i>time</i>.</p> <i>Related topics:</i><br> <strong><a href="#localtime">localtime()</a>, <a href="#gmtime">gmtime()</a>, <a href= "#strftime">strftime()</a>, <a href="#ctime">ctime()</a>,</strong> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -