How to convert time format

조회 수: 15 (최근 30일)
L
L 2019년 4월 24일
댓글: Walter Roberson 2019년 5월 3일
I am trying to convert the following time format (example): 1975-092T00:04:17.237 to just seconds. I have read the page https://www.mathworks.com/help/matlab/ref/datenum.html but this specific time format is giving me trouble (it is earth received time). Has anyone worked with this time format or have a simple way of converting? My data is a matrix wherein one column is time in this format. Thank you!
  댓글 수: 1
Adam Danz
Adam Danz 2019년 4월 24일
What is 092T00?

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

채택된 답변

Walter Roberson
Walter Roberson 2019년 4월 24일
datetime(TheString, 'InputFormat', 'uuuu-DDD''T''HH:mm:ss.SSS')
Note that this date does not include any timezone information. The 'T' does not imply anything about time zone.
It would be common for times in this format to be immediately followed by some timezone information such as ending in Z
  댓글 수: 6
Peter Perkins
Peter Perkins 2019년 5월 3일
" I was trying to convert this to just seconds"
L, you may also mean, "convert to seconds from some reference time." Create the reference as a datetime and subtract. The result is a duration:
> dt = datetime('1975-092T00:04:17.237', 'Format', "uuuu-DDD'T'HH:mm:ss.SSS")
dt =
datetime
1975-092T00:04:17.237
>> et = dt - datetime(1970,1,1)
et =
duration
46008:04:17
>> et.Format = 's'
et =
duration
165629057.237 sec
Walter's right that such timestamps often have a time zone suffix. Also "earth received time" makes me think that maybe you care about leap seconds, in which case you might want to set the result's timezone to 'UTCLeapSeconds':
>> et2 = dt - datetime(1970,1,1,'TimeZone','UTCLeapSeconds')
pt2 =
duration
46008:04:21
>> et2.Format = 's'
et2 =
duration
165629061.237 sec
Walter Roberson
Walter Roberson 2019년 5월 3일
Ah, I completely missed the significance of "earth received time".

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

추가 답변 (0개)

카테고리

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