Is there a function to santize a date vector?

1 次查看(过去 30 天)
Hi all,
I was wondering if there's a function to sanitize a date vector (or add a time in seconds to a date vector). For example, if I want to find the date and time 1 millions seconds in the future:
present = datevec(now);
look_ahead = 1e6; % fast forward 1 million seconds
% the date vector for the future
future = present;
future(end) = future(end) + look_ahead;
% print the date one million seconds in the future
future_str = datestr(future) % not what's intended
% Work around it by converting look_ahead to a time stamp.
% This work around is "clunky", loses precision, and is not guaranteed to be correct
look_ahead_stamp = look_ahead / (24*60*60); % if only all days had the same number of seconds
future_str = datestr(datenum(present) + look_ahead_stamp)
% Ideal Solution:
future = SantizeDateVec(future); % does this function exist?
datestr(future)
Any suggestions on the above would be appreciated,
Cheers, Andrew

采纳的回答

Andrei Bobrov
Andrei Bobrov 2014-3-21
future = datevec(addtodate(now,1e6,'sec'));

更多回答(0 个)

类别

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