Unix timestamp formatting with ctime in c

I am trying to format a ten-digit Unix timestamp (currently a string) using ctime.

However, ctime () expects a parameter of type time_t, not a string.

What should I do before I can use ctime? In other words, can I easily convert a string to time_t?

+6
source share
2 answers

You say you have something like 1346426869 as a string and want it to be time_t?

time_t raw_time = atoi("1346426869"); printf("current time is %s",ctime(&raw_time)); > current time is Fri Aug 31 11:27:49 2012 
+9
source

The time_t type is an integer. This is the number of seconds since the Age. First you need to parse the string.

Start here:

http://www.gnu.org/software/libc/manual/html_node/General-Time-String-Parsing.html#General-Time-String-Parsing

and make your way from there.

0
source

Source: https://habr.com/ru/post/924656/


All Articles