필터 지우기
필터 지우기

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'));

추가 답변 (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