The ctime
function returns a string containing the local time. It is based on the timer argument given to the function.
The ctime
function can be accessed via time.h
library.
The parameter of the ctime
function is a pointer to a time_t
object.
The time_t
datatype is used to store system time values. It contains a calendar time value that is the pointer to which is given as a parameter to the function.
char *ctime(const time_t *timer)
The ctime
function returns a string of readable text containing the date and time.
The return string has the format:
Www Mmm dd hh:mm:ss yyyy
where:
Www
: Day of the week
Mmm
: Month of the year
dd
: Day of the month
hh
: Hour of the day
mm
: Minute of the hour
ss
: Second of the minute
yyyy
: Year
#include <stdio.h>#include <time.h> // this library contains ctime functionint main() {time_t current_time; // this variable stores current time statetime(¤t_time);printf("Time returned in the specified format is: %s", ctime(¤t_time));return 0;}
Free Resources