convert date to number
Show older comments
Hi,
I want to convert this : 00:01:36.480
HH:MM:SS.fff where f is a millisecond
into this number 000136480
is it possible?
my version of matlab R2019b
thank you
3 Comments
the cyclist
on 15 Mar 2020
What's the format of your input? Is it a character array? String? Something else?
c = '00:01:36.480'; % Character array
s = "00:01:36.480"; % String
What format do you want for your output? Another character array or string? (You ask for a "number", but those leading zeros look like you want text.)
Mathis Faure
on 15 Mar 2020
Mathis Faure
on 15 Mar 2020
Answers (1)
Star Strider
on 15 Mar 2020
Edited: Star Strider
on 15 Mar 2020
This appears to do what you want:
This = '00:01:36.480';
NowThis = datetime(This, 'InputFormat','HH:mm:ss.SSS', 'Format','HHmmssSSS')
producing:
NowThis =
datetime
000136480
EDIT — (15 Mar 2020 at 14:51)
To get a character array output:
This = '00:01:36.480';
NowThis = string(datetime(This, 'InputFormat','HH:mm:ss.SSS', 'Format','HHmmssSSS'))
ThisStr = sscanf(NowThis, '%s')
producing:
ThisStr =
'000136480'
Categories
Find more on Data Type Conversion 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!