How to use the asctime() function in C

2 Answers

0 votes
#include <stdio.h>
#include <time.h>

int main()
{
	time_t timet;

	time(&timet);

	struct tm* p = localtime(&timet);

	printf("%s", asctime(p));

	return 0;
}



/*
run:

Sat Jan  7 22:27:19 2023

*/

 



answered Jan 7, 2023 by avibootz
0 votes
#include <stdio.h>
#include <time.h>

int main()
{
	struct tm tm = *localtime(&(time_t) { time(NULL) });

	printf("%s", asctime(&tm));

	return 0;
}




/*
run:

Sat Jan  7 22:33:33 2023

*/

 



answered Jan 7, 2023 by avibootz
...