필터 지우기
필터 지우기

Date conversion in a number format

조회 수: 1 (최근 30일)
Md
Md 2014년 3월 27일
댓글: Walter Roberson 2014년 3월 27일
Hey guys
I have an excel file with the date format like this: '03/06/2014 11:39:04.324 PM' I want to convert this date format into (yyyymmddhhmmssSSS)20140306233904324. If the time is PM, then the hour should be in the format of 24 hours. Thanks in advance.

채택된 답변

Chandrasekhar
Chandrasekhar 2014년 3월 27일
clc
str = '03/06/2014 11:39:04.324 PM';
[date,rem] = strtok(str,'/');
[month,rem]= strtok(rem,'/');
[year,rem]=strtok(rem,' ');
year = regexprep(year,'/','');
[hours,rem]=strtok(rem,':');
hours = regexprep(hours,' ','');
[mins,rem] = strtok(rem,':');
[sec,rem]=strtok(rem,'.');
sec = regexprep(sec,':','');
[msec,rem]= strtok(rem,' ');
[msec,y] = strtok(msec,'.');
if(strcmp(rem,' PM'))
hours = str2num(hours);
hours = hours+12;
hours = num2str(hours);
end
totaltime = [year date month hours mins sec msec]

추가 답변 (1개)

Walter Roberson
Walter Roberson 2014년 3월 27일
datestr(datevec('03/06/2014 11:39:04.324 PM', 'MM/DD/YYYY hh:mm:ss.fff PM'), 'YYYYMMDDhhmmssfff')
  댓글 수: 2
Chandrasekhar
Chandrasekhar 2014년 3월 27일
so simple..
Walter Roberson
Walter Roberson 2014년 3월 27일
You could also use datenum instead of datevec but I think datevec should be more resistant to round-off.

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

카테고리

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