How to change datetime format?

73 vues (au cours des 30 derniers jours)
Sim
Sim le 13 Juin 2023
Commenté : Sim le 13 Juin 2023
Given this:
datetime('02-Jul-2023','InputFormat','dd-MMM-yyyy')
ans = datetime
02-Jul-2023
How can I get this format ?
datetime('02-Jul-2023 22:00:00')
ans = datetime
02-Jul-2023 22:00:00

Réponse acceptée

Stephen23
Stephen23 le 13 Juin 2023
Modifié(e) : Stephen23 le 13 Juin 2023
You can specify different formats for the input and display:
DT = datetime('02-Jul-2023','InputFormat','dd-MMM-yyyy', 'Format','dd-MMM-yyyy HH:mm:ss')
DT = datetime
02-Jul-2023 00:00:00
If it is an existing DATETIME object, then simply modify its FORMAT property as you wish, e.g.:
DT.Format = 'uuuuDDD' % ISO 8601 day-number format
DT = datetime
2023183
  1 commentaire
Sim
Sim le 13 Juin 2023
Great @Stephen23!!!! Thanks a lot !! :-)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by