combine integers into date

1 回表示 (過去 30 日間)
Munsell Randall
Munsell Randall 2017 年 11 月 2 日
コメント済み: Andrei Bobrov 2017 年 11 月 2 日
i have a date in the form of numbers:
year = 2016
month = 6
day = 2
hour = 3
minute = 5
second = 1
How can I combine these values into a date format such as "06/02/2016 03:05:01"
I tried combining into a string but since the variables are only one digit, when i run:
datetime(prod_time,'InputFormat','dd-MM-yyyy HH:mm:ss')
i get:
Error using datetime (line 616)
Unable to parse '6/23/2017 18:6:9' as a date/time using the format 'dd-MM-yyyy HH:mm:ss'.
I'm assuming it's because they are looking for double digits but my variables are only single. How do I get around this?
I'm trying to do this with dynamic data that is being read in from another file.

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 11 月 2 日
y = 2016
M = 6
d = 2
h = 3
m = 5
s = 1
datetime(y,M,d,h,m,s,'F','MM/dd/uuuu HH:mm:ss')
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 11 月 2 日
Which MATLAB version are you using? The above code works for me in R2017b.
Andrei Bobrov
Andrei Bobrov 2017 年 11 月 2 日

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

その他の回答 (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