how to convert timestamps to number of seconds

48 Ansichten (letzte 30 Tage)
Chinonso Collins Unaichi
Chinonso Collins Unaichi am 29 Apr. 2016
Bearbeitet: Stephen23 am 29 Apr. 2016
Hi, I have a data that has a column of timestamps as seen below, how can I convert the timestamps to number of seconds? '2013-01-01 00:00:00' '2013-01-01 00:00:01' '2013-01-01 00:00:02' I get some large number like735235 735235.000011574 735235.000023148 735235.000034722 when I used datenum(), are I guess these numbers are just the format in which the date and time are stored. How do get the time in seconds?

Akzeptierte Antwort

Stephen23
Stephen23 am 29 Apr. 2016
Bearbeitet: Stephen23 am 29 Apr. 2016
What do you mean by "number of seconds" ? The number of seconds from when? From what epoch? (without an epoch it is meaningless to count seconds).
The definition of MATLAB's serial date number is clearly defined: "the number of days from January 0, 0000". If you want this time in seconds then simply multiply the serial date number by the number of seconds in a day. Note that these numbers will be much larger!
If you only need the seconds component of those timestamps, then use datevec, and take a look at the sixth column of data:
>> C = {'2013-01-01 00:00:00' '2013-01-01 00:00:01' '2013-01-01 00:00:02'};
>> V = datevec(C)
V =
2013 1 1 0 0 0
2013 1 1 0 0 1
2013 1 1 0 0 2
>> V(:,6)
ans =
0
1
2

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by