How can I convert runtime into datetime?
조회 수: 11 (최근 30일)
이전 댓글 표시
I have a this type of run time data
142369240.800000
142369240.800000
142369241
142369241.200000
142369241.200000
I am using the below datetime option to convert into d-MMM-y HH:mm:ss.sss, but getting results in CE. Please can you help us out? thanks
t = datetime(142369240.800000,'ConvertFrom','datenum','Format','d-MMM-y HH:mm:ss.sss')
t =
datetime
389793 CE
댓글 수: 0
채택된 답변
Steven Lord
2020년 6월 11일
There's a Note in the description of the Format property on the documentation page for datetime that states "Datetime values later than 144683 years CE or before 140743 BCE display only the year numbers, regardless of the specified Format value."
You could break this up into year, month, and day values if your value actually represents a date.
>> dt1 = datetime(142369240.800000, 'ConvertFrom' ,'datenum');
>> [y, m, d] = ymd(dt1)
y =
389793
m =
9
d =
26
But since you mentioned runtime, I'm guessing your number doesn't represent a date. Does it represent a number of seconds, milliseconds, microseconds, or the like? If so you probably don't want to create a datetime but instead want a duration.
duSeconds = seconds(142369240.8)
years(duSeconds) % about four and a half years
댓글 수: 2
Steven Lord
2020년 6월 12일
편집: Steven Lord
2020년 6월 12일
run time is the machine run time and is in seconds. I actually wanted it in dd-MM-yyyy HH:mm:ss.SSS format.
Do you know when the machine started running? Trying to convert say 10 seconds to a date and time doesn't work, but trying to convert 10 seconds from right now does.
s = seconds(10);
tenSecondsFromNow = datetime('now')+s % works
tenSecondsAsDatetime = datetime(s) % does not work
That's like the person who calls up a business and asks "How far away are you?" Without knowing where the caller is, that question is unanswerable (except in general terms, like "Less than a million miles.")
But I cannot still use this variable to plot other variables against time, so I used datetime function to convert it and got the below parse error.
t = datetime(d,'InputFormat','dd-MM-yyyy HH:mm:ss.SSS', 'Format', 'yyyy-MM-dd HH:mm:ss.SSS');
That's correct. d starts off '02-22-2017'. What's the 22nd month of the year? Try this, with the 'dd' and 'MM' parts of the InputFormat swapped:
t = datetime(d,'InputFormat','MM-dd-yyyy HH:mm:ss.SSS', ...
'Format', 'yyyy-MM-dd HH:mm:ss.SSS');
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!