필터 지우기
필터 지우기

I have an array of date time values. How do I separate Date and time and enter it in separate columns in excel?

조회 수: 8 (최근 30일)
My Output is a 17 x 1 cell array of date series eg:
'19-Apr-2016 11:29:31'
'27-Apr-2016 00:05:59'
'31-Mar-2016 18:35:46'....etc
I would like to separate the date and time formats and display date alone in a column in excel and time alone in another column in excel spreadsheet. Please help me with the same.

채택된 답변

Kevin
Kevin 2016년 5월 5일
>> d = datetime({'19-Apr-2016 11:29:31'; '27-Apr-2016 00:05:59'; '31-Mar-2016 18:35:46'})
d =
19-Apr-2016 11:29:31
27-Apr-2016 00:05:59
31-Mar-2016 18:35:46
>> d.Format = 'dd-MMM-yyyy';
>> column1 = cellstr(d) % Cell array of strings.
column1 =
'19-Apr-2016'
'27-Apr-2016'
'31-Mar-2016'
>> d.Format = 'hh:mm:ss';
>> column2 = cellstr(d) % Cell array of strings.
column2 =
'11:29:31'
'00:05:59'
'18:35:46'
  댓글 수: 3
William D
William D 2018년 2월 9일
I am not sure if it is due to this being posted for an older version of Matlab; however, on Matlab 2017b, in order obtain the time output in a 24h format the following syntax must be used:
>> d.Format = 'HH:mm:ss';
Reference the following link for more variations:
https://www.mathworks.com/help/matlab/ref/datetime.html
properties -> format - display format -> All Date and Time formats
Steph
Steph 2019년 2월 11일
Kevin's code did not produce the desired results in 2017b for 24 hour format. William's correction worked for 24 hr format in 2017b.

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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 5월 5일
편집: Azzi Abdelmalek 2016년 5월 5일
v={'19-Apr-2016 11:29:31'
'27-Apr-2016 00:05:59'
'31-Mar-2016 18:35:46'}
w=regexp(v,'\s+','split')
out=reshape([w{:}],2,[])'

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by