DateConvert

版本 1.1.0.0 (5.1 KB) 作者: Jan
Simple but fast date conversion: 1.3% of DATESTR time, 20% of DATEVEC/ DATENUM time
1.8K 次下载
更新时间 2010/7/2

查看许可证

DateConvert: Simple but fast date conversion

DateConvert converts the DATESTR(0) format to a date vector or serial date number and backwards.

Matlab's DATENUM, DATEVEC and DATESTR accept a variety of inputs, but in consequence they are slow. If the input format is exactly known, the conversion can be much faster:
DATENUM('17-Oct-2009 11:08:23'): 2.97 sec
DateConvert('17-Oct-2009 11:08:23', 'number'): 0.039 sec
=> 1.3% (1000 loops, 1.5GHz Pentium-M, Matlab 7.7)

DateConvert does *not* validate the input date as Matlab's date functions:
DATEVEC('32-Feb-2008 25:62:63') replies [2008 3 4 2 2 7],
DateConvert('32-Feb-2008 25:61:67' , 'vector') replies [2008 2 32 25 61 67] !
So DateConvert is nearly trivial, but optimized for speed. I needed it for sorting 200'000 time stamps and reduced the time from 217 to 11 sec.

Please run the unit-test TestDateVec to check validity and speed.

Tested: Matlab 6.5, 7.7, 7.8, WinXP, 32bit.
Pure Matlab code, so compatibility to MacOS, Linux, 64 bit is expected.
English month names are needed.

Suggestions and question by email or in the comment section are very welcome.

See also: DateStr2Num (Jan Simon)
http://www.mathworks.com/matlabcentral/fileexchange/28093

引用格式

Jan (2024). DateConvert (https://www.mathworks.com/matlabcentral/fileexchange/25594-dateconvert), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2009a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.1.0.0

Call to external function "isEqualTol" removed from the test function. No changes in the main function.

1.0.0.0