⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datenum2.m

📁 非常好的差分进化matlab程序
💻 M
字号:
function dateNr = datenum2(dateStr)
%DATENUM2  Return serial date number.
%		N = DATENUM2(STR) returns the serial date number for the given date 
%		string STR. Function DATENUM2 is a wrapper for DATENUM which replaces 
%		german month abbreviations like "Okt" by the english versions like 
%		"Oct" before forwarding the string to function DATENUM.
%
%		Function DATENUM2 first tries to build a date vector from the given
%		string for performance reasons. However, only date format 0
%		(dd-mmm-yyyy HH:MM:SS) is supported for this. If the given date string
%		is in a different format, the string is forwarded to function DATENUM.
%
%		Example:
%		n = datenum2('13-M鋜-1978 15:55:00');
%
%		Markus Buehren
%		Last modified 03.02.2008 
%
%		See also DATENUM.

tokenCell = regexp(dateStr, '(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+)', 'tokens');
tokenCell = tokenCell{1};
if length(tokenCell) == 6
	% supported date format (at least it seems so)

	% get month
	switch tokenCell{2}
		case 'Jan'
			month = 1;
		case 'Feb'
			month = 2;
		case {'Mar', 'M鋜', 'Mrz'}
			month = 3;
		case 'Apr'
			month = 4;
		case {'May', 'Mai'}
			month = 5;
		case 'Jun'
			month = 6;
		case 'Jul'
			month = 7;
		case 'Aug'
			month = 8;
		case 'Sep'
			month = 9;
		case {'Oct', 'Okt'}
			month = 10;
		case 'Nov'
			month = 11;
		case {'Dec', 'Dez'}
			month = 12;
		otherwise
			% obviously the data format is not supported
			disp('Date format not supported (1)');
			dateNr = datenum(translatedatestr(dateStr));
			return
	end

	dateVec = [...
		str2double(tokenCell{3}), ... % year
		month, ...                    % month
		str2double(tokenCell{1}), ... % day
		str2double(tokenCell{4}), ... % hours
		str2double(tokenCell{5}), ... % minutes
		str2double(tokenCell{6}), ... % seconds
		];
	dateNr = datenum(dateVec);

else
	% unknown date format
	disp('Date format not supported (2)');
	dateNr = datenum(translatedatestr(dateStr));
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function dateStr = translatedatestr(dateStr)
%TRANSLATEDATESTR  Translate german date string to english version.
%		STR = TRANSLATEDATESTR(STR) converts a german date string like 
%		  13-M鋜-1978 15:55:00
%		to the english version
%		  13-Mar-1978 15:55:00.
%		This is needed on some systems if function DIR returns german date
%		strings.

dateStr = strrep(dateStr, 'Mrz', 'Mar');
dateStr = strrep(dateStr, 'M鋜', 'Mar');
dateStr = strrep(dateStr, 'Mai', 'May');
dateStr = strrep(dateStr, 'Okt', 'Oct');
dateStr = strrep(dateStr, 'Dez', 'Dec');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -