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

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 = datetime
03-Nov-2018
t.Format = 'dd-MMM-yyyy HH:mm:ss'
t = datetime
03-Nov-2018 00:00:00

댓글을 달려면 로그인하십시오.

 채택된 답변

jonas
jonas 2018년 11월 11일
편집: jonas 2018년 11월 11일

1 개 추천

Not sure why you'd want to convert from datetime to datestr, but here's your solution:
datestr(t,'dd-mmm-yyyy HH:MM:SS')

추가 답변 (1개)

Martin
Martin 2018년 11월 11일

0 개 추천

thanks for answer. Let me say whats confusing me. If I use
t = datetime('03-Nov-2018 00:00:00','InputFormat','dd-MMM-yyyy HH:mm:ss');
Here the format is 'dd-MMM-yyyy HH:mm:ss' (the string is input)..
On the other hand with datestr I now use this (thanks jonas)
datestr(t,'dd-mmm-yyyy HH:MM:SS')
the format is 'dd-mmm-yyyy HH:MM:SS'.
Im confused since the format
'dd-MMM-yyyy HH:mm:ss' ~= 'dd-mmm-yyyy HH:MM:SS'

댓글 수: 3

jonas
jonas 2018년 11월 11일
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
Martin 2018년 11월 11일
yeah okay, a bit strange in my opinion. Anyway, now it works thanks to you :)
Stephen23
Stephen23 2021년 12월 3일
편집: Stephen23 2021년 12월 3일
"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:

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Dates and Time에 대해 자세히 알아보기

제품

질문:

2018년 11월 11일

편집:

2021년 12월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by