フィルターのクリア

Is there a function to santize a date vector?

1 回表示 (過去 30 日間)
Andrew
Andrew 2014 年 3 月 21 日
コメント済み: Andrew 2014 年 3 月 21 日
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'));
  1 件のコメント
Andrew
Andrew 2014 年 3 月 21 日
Thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by