I'm trying to format a 10-digit Unix time stamp (currently a string) using ctime.
However, ctime() expects a parameter of type time_t, not a string.
What must I do before I can use ctime? In other words, can I easily convert the string into a time_t?
Remarks. Unix time represents the number of seconds that have elapsed since 1970-01-01T00:00:00Z (January 1, 1970, at 12:00 AM UTC). It does not take leap seconds into account. This method returns the number of milliseconds in Unix time.
Unix time is a way of representing a timestamp by representing the time as the number of seconds since January 1st, 1970 at 00:00:00 UTC. One of the primary benefits of using Unix time is that it can be represented as an integer making it easier to parse and use across different systems.
Unix epoch timestamps are supported in the following formats: 10 digit epoch time format surrounded by brackets (or followed by a comma). The digits must be at the very start of the message. For example, [1234567890] or [1234567890, other] followed by the rest of the message.
You're saying you have something like 1346426869 as a string and want it to be a 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With