0

Stored that time format in some other file. And retrieve this as string. How to change this to time format again.

user10769166
  • 39
  • 1
  • 7

1 Answers1

0

You can use strptime to parse the time, and then mktime to convert it to a time_t

const char *time_details = "Thu Oct 3 18:45:10 2019";
struct tm tm;

// %a or %A
// The weekday name according to the current locale, in abbreviated form or the full name.
// %b or %B or %h
// The month name according to the current locale, in abbreviated form or the full name.


// the field descriptors must match the string format you are providing. 
strptime(time_details, "%a %b %d %H:%M:%S %Y", &tm);
time_t t = mktime(&tm);

You can find the detailed usage of input field descriptors at strptime(3)

Bhawan
  • 2,441
  • 3
  • 22
  • 47