asctime

From cppreference.com
< c‎ | chrono
Defined in header <time.h>
char* asctime( const tm* time_ptr );

Converts given calendar time tm to a textual representation. The resulting string has the following format:

Www Mmm dd hh:mm:ss yyyy\n
  • Www - the day of the week (one of Mon, Tue, Wed, Thu, Fri, Sat, Sun).
  • Mmm - the month (one of Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
  • dd - the day of the month
  • hh - hours
  • mm - minutes
  • ss - seconds
  • yyyy - years

The function does not support localization.

Contents

[edit] Parameters

time_ptr - pointer to a tm object specifying the time to print

[edit] Return value

pointer to a static null-terminated character string holding the textual representation of date and time, followed by a new line character. The string may be shared between asctime and ctime, and may be overwritten on each invocation of any of those functions.

[edit] Notes

This function returns a pointer to static data and is not thread-safe. POSIX marks this function obsolete and recommends strftime instead.

The behavior is undefined if the output string would be longer than 25 characters, if timeptr->tm_wday or timeptr->tm_mon are not within the expected ranges, or if timeptr->tm_year exceeds INT_MAX-1990.

Some implementations handle timeptr->tm_mday==0 as meaning the last day of the preceding month.

[edit] Example

#include <stdio.h>
#include <time.h>
 
int main(void)
{
    time_t rawtime;
    struct tm *timeinfo;
 
    time(&rawtime);
    timeinfo = localtime(&rawtime);
    printf("%s", asctime(timeinfo));
 
    return 0;
}

Possible output:

Wed Oct  9 10:28:03 2013

[edit] See also

converts a time_t object to a textual representation
(function)
converts a tm object to custom textual representation
(function)
C++ documentation for asctime