Effacer les filtres
Effacer les filtres

datetime conversion lose nanoseconds

7 vues (au cours des 30 derniers jours)
Andrea Sbaragli
Andrea Sbaragli le 21 Mai 2021
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 commentaire
Stephen23
Stephen23 le 21 Mai 2021
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

Connectez-vous pour commenter.

Réponses (1)

Steven Lord
Steven Lord le 21 Mai 2021
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

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by