How get time and date from timestamp

Hi everyone,
I am trying to get date and time from a timestamp number and show it in my local time zone. This timestamp is got from a JSON data. Which is the correct way to do that? I was seeing time API but I ended up a little bit confused.

Thanks for your help.
Best Regards

I don’t understand how it’s related to mbed, it sounds like a general c++ question that should be asked on stackoverflow (if it’s not already answered there).

Can you show us the timestamp? And also the expected output, with formatting if any.

1 Like

Hi, my question was about how to use Time API from mbed in order to get the the date and time from timestamp (ex 1612841919) in my localtimezone or diferent UTC.

Best Regards

From c - Convert Epoch Time string to Time - Stack Overflow

time_t c = 1612841919;
auto date = ctime( &c );
1 Like

thanks for your reply. Finally I implemented the code below and works but still with problems. The output that gives me Mbed when I compiled and run code in LPC1768 is “10/2/21,1:42:57” but when I run the same code in a C++ online compiler is “10/02/21,01:42:57”. In numbers less than 10, strftime is not adding left zero value and I need the second format. Is there a simple way to do that? because in documentation the function with these format options should work. Thanks for your help

#define UTC    -3
...
char dateTimeString[20];
time_t timestampDataInt = 0;
timestampDataInt = (time_t)atoll("1612932177")-abs(UTC*3600);
time_t infoTime = timestampDataInt;
strftime(dateTimeString, 20, "%d/%m/%y,%T",localtime(&infoTime));