Share Code and Data Across Locales
In this section...
“Write Locale-Independent Date and Time Code” on page 7-20
“Write Dates in Other Languages” on page 7-21
“Read Dates in Other Languages” on page 7-21
Write Locale-Independent Date and Time Code
Follow these best practices when sharing code that handles dates and time with MATLAB® users in
other locales. These practices ensure that the same code produces the same output display and that
output files containing dates and time are read correctly on systems in different countries or with
different language settings.
Create language-independent datetime values. That is, create datetime values that use month
numbers rather than month names, such as 01 instead of January. Avoid using day of week names.
For example, do this:
t = datetime('today','Format','yyyy-MM-dd')
t = datetime
2021-09-01
instead of this:
t = datetime('today','Format','eeee, dd-MMM-yyyy')
t = datetime
Wednesday, 01-Sep-2021
Display the hour using 24-hour clock notation rather than 12-hour clock notation. Use the 'HH'
identifiers when specifying the display format for datetime values.
For example, do this:
t = datetime('now','Format','HH:mm')
t = datetime
15:32
instead of this:
t = datetime('now','Format','hh:mm a')
t = datetime
03:32 PM
When specifying the display format for time zone information, use the Z or X identifiers instead of the
lowercase z to avoid the creation of time zone names that might not be recognized in other languages
or regions.
7 Dates and Time
7-20
In this section...
“Write Locale-Independent Date and Time Code” on page 7-20
“Write Dates in Other Languages” on page 7-21
“Read Dates in Other Languages” on page 7-21
Write Locale-Independent Date and Time Code
Follow these best practices when sharing code that handles dates and time with MATLAB® users in
other locales. These practices ensure that the same code produces the same output display and that
output files containing dates and time are read correctly on systems in different countries or with
different language settings.
Create language-independent datetime values. That is, create datetime values that use month
numbers rather than month names, such as 01 instead of January. Avoid using day of week names.
For example, do this:
t = datetime('today','Format','yyyy-MM-dd')
t = datetime
2021-09-01
instead of this:
t = datetime('today','Format','eeee, dd-MMM-yyyy')
t = datetime
Wednesday, 01-Sep-2021
Display the hour using 24-hour clock notation rather than 12-hour clock notation. Use the 'HH'
identifiers when specifying the display format for datetime values.
For example, do this:
t = datetime('now','Format','HH:mm')
t = datetime
15:32
instead of this:
t = datetime('now','Format','hh:mm a')
t = datetime
03:32 PM
When specifying the display format for time zone information, use the Z or X identifiers instead of the
lowercase z to avoid the creation of time zone names that might not be recognized in other languages
or regions.
7 Dates and Time
7-20
