Namespaces
Variants
Views
Actions

Difference between revisions of "c/chrono/ctime"

From cppreference.com
< c‎ | chrono
m (Text replace - "{{example c" to "{{example")
m (Text replace - "{{cpp|" to "{{c|")
Line 5: Line 5:
 
}}
 
}}
  
Converts given time since epoch to a calendar local time and then to a textual representation, as if by calling {{cpp|asctime(localtime(time))}}. The resulting string has the following format:
+
Converts given time since epoch to a calendar local time and then to a textual representation, as if by calling {{c|asctime(localtime(time))}}. The resulting string has the following format:
  
 
{{source|Www Mmm dd hh:mm:ss yyyy}}
 
{{source|Www Mmm dd hh:mm:ss yyyy}}
Line 21: Line 21:
 
===Parameters===
 
===Parameters===
 
{{param list begin}}
 
{{param list begin}}
{{param list item | time | pointer to a {{cpp|time_t}} object specifying the time to print}}
+
{{param list item | time | pointer to a {{c|time_t}} object specifying the time to print}}
 
{{param list end}}
 
{{param list end}}
  
 
===Return value===
 
===Return value===
  
pointer to a static null-terminated character string holding the textual representation of date and time. The string may be shared between {{tt|asctime}} and {{cpp|ctime}}, and may be overwritten on each invocation of any of those functions.
+
pointer to a static null-terminated character string holding the textual representation of date and time. The string may be shared between {{tt|asctime}} and {{c|ctime}}, and may be overwritten on each invocation of any of those functions.
  
 
===Notes===
 
===Notes===
This function returns a pointer to static data and is not thread-safe. In addition, it modifies the static {{cpp|tm}} object which may be shared with {{cpp|gmtime}} and {{cpp|localtime}}. POSIX marks this function obsolete and recommends {{cpp|strftime}} instead.
+
This function returns a pointer to static data and is not thread-safe. In addition, it modifies the static {{c|tm}} object which may be shared with {{c|gmtime}} and {{c|localtime}}. POSIX marks this function obsolete and recommends {{c|strftime}} instead.
  
 
The behavior may be undefined for the values of time_t that result in the string longer than 25 characters (e.g. year 10000)
 
The behavior may be undefined for the values of time_t that result in the string longer than 25 characters (e.g. year 10000)

Revision as of 16:52, 13 April 2012

Template:c/chrono/c/sidebar

Defined in header <time.h>
char* ctime( const time_t* time );

Converts given time since epoch to a calendar local time and then to a textual representation, as if by calling asctime(localtime(time)). The resulting string has the following format:

Www Mmm dd hh:mm:ss yyyy
  • 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

Parameters

time - pointer to a time_t object specifying the time to print

Return value

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

Notes

This function returns a pointer to static data and is not thread-safe. In addition, it modifies the static tm object which may be shared with gmtime and localtime. POSIX marks this function obsolete and recommends strftime instead.

The behavior may be undefined for the values of time_t that result in the string longer than 25 characters (e.g. year 10000)

Example

See also

Template:c/chrono/c/dcl list asctimeTemplate:c/chrono/c/dcl list strftime