datetime conversion lose nanoseconds

조회 수: 8 (최근 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
Stephen23
Stephen23 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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by