Convert datetime to string

How can I convert
datetime('now','TimeZone','local','Format','d-MMM-y HH:mm:ss')
to a string with this structure: 12-Oct-2022_18:12:17

 采纳的回答

Use string after formatting your datetime.
dt = datetime('now','TimeZone','local','Format','d-MMM-y HH:mm:ss')
dt = datetime
12-Oct-2022 18:30:14
dtstr = string(dt)
dtstr = "12-Oct-2022 18:30:14"

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Dates and Time 的更多信息

产品

版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by