How can I convert runtime into datetime?
12 ビュー (過去 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!