How can I get default/local Date/Time patterns/formats?

4 visualizaciones (últimos 30 días)
Deniss Sipcenko
Deniss Sipcenko el 6 de Abr. de 2016
Respondida: Ravi Chaitanya el 29 de Dic. de 2022
Dear all,
Problem: How can I get default/local Date/Time patterns/ format s?
There are a lot of functions that use format as input parameter:
datenum ("datestr", format);
datestr (DATE, format);
...
But which function returns format as output parameter?
For example, in Powershell I can get it like that:
PS H:\>(Get-Culture).DateTimeFormat.ShortDatePattern
yyyy-MM-dd
PS H:\> (Get-Culture).DateTimeFormat.ShortTimePattern
HH:mm

Respuestas (1)

Ravi Chaitanya
Ravi Chaitanya el 29 de Dic. de 2022
Hello Deniss,
As per my understanding, you want to know if there is a command to get the date/time format.
It is possible to do so by using “datetime”. Below is the code snippet illustrating the same:
curDateTime=datetime;
curDateTime.Format
The output of the above command tells the format for date and time.
Further, it is also possible to specify the format you want to use as given below:
curDateTime.Format='yyyy-MM-dd HH:mm';
curDateTime
The output of the above snippet will output the date and time in the specified format.
Please refer to the MathWorks documentation on datetime to know more.
Thanks!

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by