How to set mmmm dd, yyyy as per our choice in the datestr command?

조회 수: 1 (최근 30일)
Megha
Megha 2019년 8월 11일
편집: dpb 2019년 8월 11일
How to set mmmm dd, yyyy as per our choice in the following command?
datestr(hours(50),'mmmm dd, yyyy HH:MM:SS')
It is normally taking:
'January 02, 0000 02:00:00'
I wish to get:
'September 02, 2017 02:00:00'
as my o/p.
Can anyone help!

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019년 8월 11일
편집: KALYAN ACHARJYA 2019년 8월 11일
>> datestr(years(2019),'mmmm dd, yyyy HH:MM:SS')
ans =
'December 30, 2018 14:34:48'
For any other format please check here
  댓글 수: 1
Megha
Megha 2019년 8월 11일
ok let me explain other way round!
I only have time in hours like 20, 30, 40, 50... and i wish to convert that hours using
datestr(hours(50),'mmmm dd, yyyy HH:MM:SS')
to obtain
'September 02, 2017 02:00:00'
So is there any way to set specific year and month instead?

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


dpb
dpb 2019년 8월 11일
datestr(datetime(2017,9,2,2,0,0))
  댓글 수: 2
Megha
Megha 2019년 8월 11일
ok let me explain other way round!
I only have time in hours like 20, 30, 40, 50... and i wish to convert that hours using
datestr(hours(50),'mmmm dd, yyyy HH:MM:SS')
to obtain
'September 02, 2017 02:00:00'
So is there any way to set specific year and month instead?
dpb
dpb 2019년 8월 11일
편집: dpb 2019년 8월 11일
Well, not without some reference point, no. 50 hours all by itself is only a duration--how is it to know what to be referenced/correlated to? With the arbitrary and a priori knowledge that 50 hours from that point is to be 0200 on the second day of September of the given year, then sure:
datestr(datetime(2017,9,0,50,0,0))
datetime will automagically roll-over hours based on calendar--but it has to have a reference point...and 0 doesn't work well; it has to be a date within the epoch.
So, something like
>> T0=datetime(2017,9,0);
>> T0+hours(20:10:50).'
ans =
4×1 datetime array
31-Aug-2017 20:00:00
01-Sep-2017 06:00:00
01-Sep-2017 16:00:00
02-Sep-2017 02:00:00
>>
might be more amenable to your wishes.

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

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by