abderrahim_05
abderrahim_05

Reputation: 465

convert a date in dd/mm/yyyy to timestamp (seconds since 01/01/1970) in C++

I'm looking for a way to convert, a formated date dd/mm/yyyy to standard timestamp. using c++ language.

thank you for your help

Upvotes: 0

Views: 1180

Answers (2)

VirgileD
VirgileD

Reputation: 757

Something like this:

struct tm tm;
time_t epoch;
strptime(your_formated_date, "%d/%m/%Y", &tm);
epoch = mktime(&tm);

Upvotes: 1

Steve Jessop
Steve Jessop

Reputation: 279225

strptime and mktime.

Be aware that timezone affects the answer, since a standard timestamp is seconds since 1970 UTC, not necessarily seconds since 1970 local time.

Also be aware that the epoch isn't guaranteed by the C++ standard to be 1970, although it is on common systems.

Upvotes: 1

Related Questions