Frustrating datetime and datestr
Show older comments
Hey I got this
hund = datetime(end_stamp, 'convertfrom','posixtime')
% which give this:
hund =
datetime
05-Nov-2018 00:00:00
Because this one hit time 00:00:00 and I use datestr i get this:
hund = datestr(hund)
hund = '05-Nov-2018'
But I need to get the exact line as a string:
hund = '05-Nov-2018 00:00:00'
Anyone have an idea ?
1 Comment
Rather than using deprecated DATESTR, it is much better to stick with the DATETIME object itself:
t = datetime('03-Nov-2018 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss')
t.Format = 'dd-MMM-yyyy HH:mm:ss'
Accepted Answer
More Answers (1)
Martin
on 11 Nov 2018
3 Comments
jonas
on 11 Nov 2018
I don't know if there is a reason, but the format differs depending on function. In datetime the month is capital letters and in datestr they are not. It is described in the documentation, but I don't know the reason for this.
Martin
on 11 Nov 2018
"I don't know if there is a reason"
The deprecated DATESTR/DATENUM, etc used a simple, consistent, venerable format presumably devised by TMW.
In contrast DATETIME uses the Unicode Locale Data Markup Language (LDML) standard for dates and times:
as documented here:
Categories
Find more on Dates and Time in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!