how to convert timestamps to number of seconds
48 views (last 30 days)
Show older comments
Chinonso Collins Unaichi
on 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?
0 Comments
Accepted Answer
Stephen23
on 29 Apr 2016
Edited: Stephen23
on 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
0 Comments
More Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!