MATLAB Answers


Date and time formate translation

Asked by Martin
on 1 Dec 2018
Latest activity Edited by Martin
on 2 Dec 2018
Accepted Answer by dpb
I need to translate those dates and time (strings)
'25-Mar-2014 13:00:00'
'07-Nov-2018 18:30:45'
to the forllowing format (in string as well):
Any idea how to handle such kind of formats? I find it pretty complex...


what does T and Z represent just curious?
Actually I Dont Know!

Sign in to comment.

1 Answer

Answer by dpb
on 1 Dec 2018
Edited by dpb
on 1 Dec 2018
 Accepted Answer

dt=datetime('25-Mar-2014 13:00:00');
fmt= 'uuuu-MMM-dd''T''HH:mm:ss.SSS''Z';
>> dt =


hmm actyally I though this would do it ( was on phone ), but the problem is that the result is not a string...
If I use datestr() on dt, I'll get
ans =
'25-Mar-2014 13:00:00'
Okay I figured it out, I could just use char(dt).
on 1 Dec 2018
Yes. datestr is a remnant of the deprecated datenum that didn't have a formatting option; it is just a particularly-scaled double.
char(dt) is the idiom if need the character array; for most purposes however, either cellstr or string is probably more useful/less coding downstream--but depends upon just why you actually need the string representation at all...
I need to get a response from a statistical data API on the internet. This API only takes this kind of format. Do you have any suggestion how to get posix time from the format? string: timestr='2014-03-25T13:00:00.000Z'?
EDIT: Okay figured out. First I use t= datetime(timestr,'Format','yyyy-MM-dd''T''HH:mm:ss.SSS''Z')
then just posixtime(t)

Sign in to comment.