Azzera filtri
Azzera filtri

datetime conversion lose nanoseconds

7 visualizzazioni (ultimi 30 giorni)
Andrea Sbaragli
Andrea Sbaragli il 21 Mag 2021
Risposto: Steven Lord il 21 Mag 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 Commento
Stephen23
Stephen23 il 21 Mag 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

Accedi per commentare.

Risposte (1)

Steven Lord
Steven Lord il 21 Mag 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

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by