Converting unix time to real time
17 views (last 30 days)
Show older comments
I want to convert Unix Time Stamp like this '1641031963.398125' in a Format like this "Friday, 21. December 2018 11:14:24.126".
I used: date_time = datestr(unix_time/86400 + datenum(1970,1,1));
but the answer is a char vector which is not the correct time:

how can I convert unix to real time? any help will be appreciated.
0 Comments
Answers (2)
Walter Roberson
on 14 Feb 2022
datetime(1641031963.398125, 'ConvertFrom', 'posixtime', 'Format', 'eeee, d. MMMM uuuu H:mm:ss.SSS')
It was not completely clear whether you wanted leading zeros on the hour or not.
0 Comments
Rik
on 14 Feb 2022
I suspect you forgot to convert the char to a value:
unix_time='1641031963.398125';
unix_time=str2double(unix_time);
date_time = datestr(unix_time/86400 + datenum(1970,1,1))
0 Comments
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!