Hi,
i have a vector of time in epoch format (read as double in Matlab). I have to convert all the elements in a format HH:MM:SS till milli or even nano seconds if it is possible.
The vector time is related to data acquired on 20th October 2021.
Can someone help me please ?
Thank you in advance

댓글 수: 1

What is the epoch time for midnight on 20th October 2021, and 1 and 60 seconds later?
.

댓글을 달려면 로그인하십시오.

 채택된 답변

Spectro
Spectro 2021년 12월 1일
편집: Spectro 2021년 12월 1일

0 개 추천

Have a look at datetime() using parameter "ConvertFrom":
epochs = [1638351674 1638351674];
datetime(epochs, 'ConvertFrom', 'epochtime')

댓글 수: 4

Thank you !
I already tried this solution, but then i had this error:
Conversion to or from epoch times is not supported for times that more
than 285Ky before or after the specified epoch
Do you have any idea about how can i solve this ?
Spectro
Spectro 2021년 12월 1일
Well, try 'posixtime' instead of 'epochtime'. Do you get the same error then?
no, but then the output is in the follow format:
5.1802e+10 CE
And i don't even know what it means :(
Spectro
Spectro 2021년 12월 1일
Attach the data please.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Giorgia Fusaroli
Giorgia Fusaroli 2021년 12월 1일

1 개 추천

FYI
I solve the problem in this way:
epochs = uint64(vector-of-epoch-data)
datetime(epochs,'ConvertFrom','epochtime','TicksPerSecond',1e9,'Format','dd-MMM-yyyy HH:mm:ss.SSSSSSSSS');
Steven Lord
Steven Lord 2021년 12월 1일
What's the unit of time a value of 1 in your epochtime represents? Seconds, microseconds, nanoseconds, etc.?
t = 6000;
start = datetime('today') % Use midnight today as the start of the epoch
start = datetime
01-Dec-2021
dt1 = datetime(t, 'ConvertFrom', 'epochtime', 'Epoch', start) % 6000 seconds after the epoch
dt1 = datetime
01-Dec-2021 01:40:00
dt2 = datetime(t, 'ConvertFrom', 'epochtime', 'Epoch', start, ...
'TicksPerSecond', 1000) % 6000/1000 seconds after the epoch
dt2 = datetime
01-Dec-2021 00:00:06
You may also want to look at the table in the entry for the dateType input argument to datetime to see if one of the provided options matches what your time data represents: 'ntp', '.net', or 'ntfs' perhaps, since they each represent a number of "clock ticks" that are a small fraction of a second?

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

태그

질문:

2021년 12월 1일

답변:

2021년 12월 1일

Community Treasure Hunt

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

Start Hunting!

Translated by