how to convert timestamps to number of seconds

43 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Stephen23
Stephen23 il 29 Apr 2016
Modificato: Stephen23 il 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

Più risposte (0)

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