datetime "PivotYear" doesn't work?
12 ビュー (過去 30 日間)
古いコメントを表示
I am trying to use datetime() to convert string dates to datenum, to use as an axis for plotting data. My input is (from debugger session):
K>> ttemp
ttemp =
10×1 string array
"8/20/19 00:00"
"8/20/19 00:01"
"8/20/19 00:02"
"8/20/19 00:03"
"8/20/19 00:04"
"8/20/19 00:05"
"8/20/19 00:06"
"8/20/19 00:07"
"8/20/19 00:08"
"8/20/19 00:09"
If I convert with datetime I get:
K>> dt = datetime(ttemp)
dt =
10×1 datetime array
20-Aug-0019 00:00:00
20-Aug-0019 00:01:00
20-Aug-0019 00:02:00
20-Aug-0019 00:03:00
20-Aug-0019 00:04:00
20-Aug-0019 00:05:00
20-Aug-0019 00:06:00
20-Aug-0019 00:07:00
20-Aug-0019 00:08:00
20-Aug-0019 00:09:00
The years are supposed to be 2019, and I'd like to fix that, so I tried to use the 'PivotYear' name/value pair:
K>> dt = datetime(ttemp,'PivotYear',2000)
dt =
10×1 datetime array
20-Aug-0019 00:00:00
20-Aug-0019 00:01:00
20-Aug-0019 00:02:00
20-Aug-0019 00:03:00
20-Aug-0019 00:04:00
20-Aug-0019 00:05:00
20-Aug-0019 00:06:00
20-Aug-0019 00:07:00
20-Aug-0019 00:08:00
20-Aug-0019 00:09:00
Why doesn't this work?
I'm using Matlab Version 9.6.0.1174912 (R2019a)
0 件のコメント
採用された回答
Lei Hou
2019 年 9 月 23 日
Hi Richard,
The pivot year has an effect only when the 'InputFormat' parameter is specified and it includes y or yy. Therefore, to solve your problem, you can use:
dt = datetime(ttemp,'InputFormat','M/dd/yy hh:mm','PivotYear',2000)
I'll contact our documentation team to improve our datetime documentation.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Calendar についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!