How to calculate time elapsed (time in GMT format)

Hi,
I have below two different times, and want to calculate time elapsed:
2017-12-13-T16:00:23.488+08:00
2017-12-13-T16:02:24.982+08:00
Many thanks in advance,

 Accepted Answer

One approach:
v = {'2017-12-13-T16:00:23.488+08:00'
'2017-12-13-T16:02:24.982+08:00'};
T = datenum(v, 'yyyy-mm-dd-THH:MM:SS.FFF')
dT = etime(datevec(T(2)),datevec(T(1))) % Elapsed Time In Seconds
dT =
121.49
NOTE — In theory, datetime can do something like this, however it will not import your data using the date format, and refuses to automatically recognise the time zone. I suppose datetime has its uses, but they frequently elude me. Anyway, the ‘classic’ functions work.

4 Comments

Sir,
I want to get the current time in the following format:
2017/12/16 10:46:18 I use: currentTime=clock datenum(currentTime) currentTime =
1.0e+03 *
2.0170 0.0120 0.0160 0.0110 0.0450 0.0382
The I convert:
datenum(currentTime)
ans =
7.3705e+05
But Can I print the time format using clock as: 2017/12/16 10:46:18?
Yes. Use the datestr (link) function:
t = clock;
ds = datestr(t, 'yyyy/mm/dd HH:MM:SS')
ds =
'2017/12/15 22:17:32'
As always, my pleasure.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!