Converting unix time to real time

조회 수: 17 (최근 30일)
Frequency b
Frequency b 2022년 2월 14일
답변: Walter Roberson 2022년 2월 14일
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.

답변 (2개)

Walter Roberson
Walter Roberson 2022년 2월 14일
datetime(1641031963.398125, 'ConvertFrom', 'posixtime', 'Format', 'eeee, d. MMMM uuuu H:mm:ss.SSS')
ans = datetime
Saturday, 1. January 2022 10:12:43.398
It was not completely clear whether you wanted leading zeros on the hour or not.

Rik
Rik 2022년 2월 14일
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))
date_time = '01-Jan-2022 10:12:43'

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by