datetime conversion lose nanoseconds

9 ビュー (過去 30 日間)
Andrea Sbaragli
Andrea Sbaragli 2021 年 5 月 21 日
回答済み: Steven Lord 2021 年 5 月 21 日
I have converted an array from epoch time in nanoseconds to datetime using the following:
t(i,1)= datetime(B(i,1),'ConvertFrom','epochtime','TicksPerSecond',1e9,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS');
the coversion is ok but once opened the array somehow the this part SSSSSSSSS is not displayed at all.
At the same time doing it without a function value per value it works...
How can I solve this issue?
  1 件のコメント
Stephen 2021 年 5 月 21 日
ms = intmax('int64');
dt = datetime(ms,'ConvertFrom','epochtime','TicksPerSecond',1e9,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS')
dt = datetime
11-Apr-2262 23:47:16.854775807


回答 (1 件)

Steven Lord
Steven Lord 2021 年 5 月 21 日
What Format did you use when you assigned the datetime in the first row of t? Was it one that did not include the nanosecond information?
format1 = 'yyyy-MM-dd HH';
t = datetime('now', 'Format', format1)
t = datetime
2021-05-21 18
format2 = 'HH-mm-ss ''on'' yyyy-MM-dd';
t(2, 1) = datetime('now', 'Format', format2)
t = 2×1 datetime array
2021-05-21 18 2021-05-21 18
The whole array uses format1 because that was the format already in use when you assigned to the second row of t. The second element of t was converted to use the existing format. If you change the array's Format both elements are displayed in the new format.
t.Format = format2
t = 2×1 datetime array
18-24-27 on 2021-05-21 18-24-27 on 2021-05-21

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by