cppreference.com -> Standard C Time & Date -> Details |
#include <time.h> char *asctime( const struct tm *ptr ); |
The function asctime() converts the time in the struct ptr to a character string of the following format:
day month date hours:minutes:seconds year\n\0
An example:
Mon Jun 26 12:03:53 2000Related topics:
#include <time.h> clock_t clock( void ); |
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_SECOND. (Note: if your compiler is POSIX compliant, then CLOCKS_PER_SECOND is always defined as 1000000.)
Related topics:#include <time.h> char *ctime( const time_t *time ); |
The ctime() function converts the calendar time time to local time of the format:
day month date hours:minutes:seconds year\n\0
using ctime() is equivalent to
asctime( localtime( tp ) );Related topics:
#include <time.h> double difftime( time_t time2, time_t time1 ); |
The function difftime() returns time2-time1, in seconds.
Related topics:#include <time.h> struct tm *gmtime( const time_t *time ); |
The gmtime() function returns the given time in Coordinated Universal Time (usually Greenwich mean time), unless it's not supported by the system, in which case NULL is returned. Warning!
Related topics:#include <time.h> struct tm *localtime( const time_t *time ); |
The function localtime() converts calendar time time into local time. Warning!
Related topics:#include <time.h> time_t mktime( struct tm *time ); |
The mktime() function converts the local time in time to calendar time, and returns it. If there is an error, -1 is returned.
Related topics:#include <time.h> size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time ); |
The function strftime() formats date and time information from time to a format specified by fmt, then stores the result in str (up to maxsize characters). Certain codes may be used in fmt to specify different types of time:
Code | Meaning |
%a | abbreviated weekday name |
%A | full weekday name |
%b | abbreviated month name |
%B | full month name |
%c | the standard date and time string |
%d | day of the month, as a number (1-31) |
%H | hour, 24 hour format (0-23) |
%I | hour, 12 hour format (1-12) |
%j | day of the year, as a number (1-366) |
%m | month as a number (1-12). Note: some versions of Microsoft Visual C++ may use values that range from 0-11. |
%M | minute as a number (0-59) |
%p | locale's equivalent of AM or PM |
%S | second as a number (0-59) |
%U | week of the year, sunday as the first day |
%w | weekday as a decimal (0-6, sunday=0) |
%W | week of the year, monday as the first day |
%x | standard date string |
%X | standard time string |
%y | year in decimal, without the century (0-99) |
%Y | year in decimal, with the century |
%Z | time zone name |
%% | a percent sign |
The strftime() function returns the number of characters put into str, or zero if an error occurs.
Related topics:#include <time.h> time_t time( time_t *time ); |
The function time() returns the current time, or -1 if there is an error. If the argument time is given, then the current time is stored in time.
Related topics: