Changing a double type cell in "HH:MM:SS" format.
16 次查看(过去 30 天)
显示 更早的评论
I have a time column which has a double type, "4.099215427200000e+09" as an example of one cell of the whole column.
Is there a way how to change the whole column format in a date format " HH:MM:SS"?
8 个评论
Bjorn Gustavsson
2020-10-6
OK, so now you've explained that the time-unit is ms (perhaps?). That takes us to the result that your first data (4.099215427200000e+09) is 47.445 days from your date-zero. If you can tell datestr what that date-zero is you've solved your problem.
采纳的回答
Steven Lord
2020-10-6
What duration do you expect 4.099215427200000e+09 to represent? If you give us one piece of a Rosetta stone we may be able to help interpret your data. Based on your equation this might be what you're looking for:
du = seconds(4.099215427200000e+09/1000);
du.Format = 'hh:mm:ss'
How did you obtain the value of about 4.099e9 from your Excel file? How did you read that data into MATLAB?
Looking at your file and manually copying the value from cell A1 into MATLAB, I think this is what you want:
du2 = seconds(47445960)/1000;
du2.Format = 'hh:mm:ss'
3 个评论
Stephen23
2020-10-7
编辑:Stephen23
2020-10-7
"I obtained the value through the calculation that I was given, which was: the given time values (Column A in picture 1)*1000/24/60/60)"
I very much doubt that, you won't get anything close to 4e9:
>> val = 47444524; % cell A1 of your Excel worksheet.
>> val*1000/24/60/60 % your own calculation.
ans =
5.4913e+05
Whatever you did to get 4e9 is something quite different, which so far you have not shown us or explained. Not that it really matters, because that very strange value does not help us anyway.
Apparently the input value is simply a duration in milliseconds (it would have saved everyone a lot of time if you had just explained that in the beginning), in which case Steven Lord's answer gives what you are looking for:
>> du = seconds(val)/1000;
>> du.Format = 'hh:mm:ss'
du =
13:10:44
>> du.Format = 'hh:mm:ss.SSS'
du =
13:10:44.524
>> round(du) % Excel rounds to the nearest second, which is an abomination.
ans =
13:10:45
更多回答(1 个)
Bjorn Gustavsson
2020-10-6
Well you get an output from datestr:
datestr(4.099215427200000e+09,'yyyy mm dd HH:MM:SS')
ans =
'3270 08 21 04:47:59'
You will have to give some additional information about the start of your time-scale, see the help and documentation of datestr, datenum ans datevec. Matlab's date-format is in fractional days since 0-0-0 0:0:0, unix-time is in seconds since 1970 01 01 00:00:00 (IIRC?).
HTH
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!