How to convert datetime('today') into utc format. Preferably [YYYY MM DD 12 0 0].

 採用された回答

Star Strider
Star Strider 2020 年 6 月 24 日

2 投票

Try this:
T = datetime('now', 'Format','yyyy MM dd HH mm ss', 'TimeZone','local') % Local Time Zone
T.TimeZone = 'Z' % Convert To UTC
producing:
T =
datetime
2020 06 23 18 19 09
T =
datetime
2020 06 24 00 19 09
.

3 件のコメント

Nathan Jalal
Nathan Jalal 2020 年 6 月 24 日
Thank you very much! Is there anyway to make sure the comes in [YYYY MM dd 12 0 0]? I need the hour, minute, and seconds to be those values exactly.
Star Strider
Star Strider 2020 年 6 月 24 日
My pleasure!
I thought that was just a formatting example.
I’m still not certain what you want.
Try this:
T = datetime('now', 'Format','yyyy MM dd 12 0 0', 'TimeZone','local') % Local Time Zone
T.TimeZone = 'Z' % Convert To UTC
Walter Roberson
Walter Roberson 2020 年 6 月 24 日
dateshift to start of hour or day.
If you need "noon" then dateshift to start of day and then add hours(12)

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および 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