필터 지우기
필터 지우기

Inverse of posix time

조회 수: 17 (최근 30일)
NoNo
NoNo 2015년 9월 28일
댓글: Peter Perkins 2020년 7월 28일
Hello,
O was wondering if there is a function in matlab that does the opposite as posix time. Indeed, I have a UNIX time (1443002431.224) and I want to convert it into a date with hour, minute and second.
How can I do it ? Does it exist a function to do this ?
Thank you very much for your help !!
NoNo

채택된 답변

Guillaume
Guillaume 2015년 9월 28일
d = datetime(1443002431.224, 'ConvertFrom', 'posixtime')
  댓글 수: 4
Haris K.
Haris K. 2020년 5월 16일
@Peter Perkins if you format the output of the resulted datetime as 'dd-MMM-yyyy HH:mm:ss.SSS' both:
unix_t = 1443002431.224;
datetime(unix_t, 'ConvertFrom', 'posixtime')
datetime(round(1000*unix_t),'ConvertFrom','epochtime',"TicksPerSecond",1000)
return the same output, i.e. 23-Sep-2015 10:00:31.224. So what is the round-off introduced?
Peter Perkins
Peter Perkins 2020년 7월 28일
Well, I misspoke, sort of.
The round-off is introduced in unix_t = 1443002431.224. That is not a value that is representable exactly in floating point. However, because of the extremely smart people who created IEEE754 etc. way back when, it turns out that 1443002431.224*1000 is exactly 1443002431224. And that multiplication happens inside datetime, without you needing to do it as in my code. That's what saves this.
I think that should be true for anything specified to milliseconds.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Emre Güngör
Emre Güngör 2018년 11월 29일
You need 2018 version
  댓글 수: 1
Steven Lord
Steven Lord 2018년 11월 29일
Not true. datetime was introduced in release R2014b and the documentation for that function in that release lists the 'ConvertFrom', 'posixtime' syntax. When I run Guillaume's code in release R2014b I receive the same answer as if I created a datetime for January 1st, 1970 and added that many seconds to it. Both those answers matched the results I received for those same computations in release R2018b and the result I received using an online UNIX epoch converter.

댓글을 달려면 로그인하십시오.


Anh Anh
Anh Anh 2019년 12월 10일
  댓글 수: 1
Rik
Rik 2019년 12월 10일
(rescued from spam filter)
Even though this isn't spam, it isn't a real answer either. There are Matlab tools available that do this, so it is not necessary to use an external website to do this conversion.

댓글을 달려면 로그인하십시오.

카테고리

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