C examples for time.h:asctime
function
<ctime> <time.h>
Convert tm structure to string
char* asctime (const struct tm * timeptr);
Parameter | Description |
---|---|
timeptr | Pointer to a tm structure that contains a calendar time broken down into its components. |
A -string containing the date and time in a human-readable format.
#include <stdio.h> #include <time.h> int main ()/*from ww w .j av a 2s . c o m*/ { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); printf ( "The current date/time is: %s", asctime (timeinfo) ); return 0; }
This program displays the local time defined by the system:
#include <time.h> #include <stdio.h> int main(void) { struct tm *ptr; time_t lt;//w w w .ja va2 s .c om lt = time(NULL); ptr = localtime(<); printf(asctime(ptr)); return 0; }