フィルターのクリア

express datetime from now, every 3h

2 ビュー (過去 30 日間)
Jeong_evolution
Jeong_evolution 2016 年 10 月 30 日
コメント済み: Jeong_evolution 2016 年 11 月 3 日
code is
---------------------------------------------------------------
t = datetime('now','TimeZone','local','Format','y-MMM-d HH');
---------------------------------------------------------------
In command,
---------------------------------------------------------------
t = 2016-Oct-31 00
---------------------------------------------------------------
But I want to express in command
---------------------------------------------------------------
t_1 = 2016-Oct-30 00
t_2 = 2016-Oct-30 03
t_3 = 2016-Oct-30 06
---------------------------------------------------------------
every 3 hour
.
.
.
please help me

採用された回答

Peter Perkins
Peter Perkins 2016 年 11 月 2 日
In addition to Walter's suggestions, it may also be possible to take advantage of the roll-over behavior of the datetime constructor:
>> datetime(2016,11,1,(0:3:36)',0,0)
ans =
13×1 datetime array
01-Nov-2016 00:00:00
01-Nov-2016 03:00:00
01-Nov-2016 06:00:00
01-Nov-2016 09:00:00
01-Nov-2016 12:00:00
01-Nov-2016 15:00:00
01-Nov-2016 18:00:00
01-Nov-2016 21:00:00
02-Nov-2016 00:00:00
02-Nov-2016 03:00:00
02-Nov-2016 06:00:00
02-Nov-2016 09:00:00
02-Nov-2016 12:00:00
  1 件のコメント
Jeong_evolution
Jeong_evolution 2016 年 11 月 3 日
Thanks. Good Information!

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

その他の回答 (1 件)

Steven Lord
Steven Lord 2016 年 10 月 30 日
Don't create individual variables. Instead use the colon operator to create a vector.
N = datetime('now');
d = N:hours(3):(N+days(1));
% or
d = N + hours(0:3:24);
  1 件のコメント
Jeong_evolution
Jeong_evolution 2016 年 11 月 3 日
Thanks. code is very simple. And good operate.

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

カテゴリ

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