MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1
t = datetime
01:51

instead of this:

t = datetime('now','Format','hh:mm a')

t = datetime
01:51 AM

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.

Assign a time zone to t.

t.TimeZone = 'America/New_York';

Specify a language-independent display format that includes a time zone.

t.Format = 'dd-MM-yyyy Z'

t = datetime
13-04-2019 -0400

If you share files but not code, you do not need to write locale-independent code while
you work in MATLAB. However, when you write to a file, ensure that any text
representing dates and times is language-independent. Then, other MATLAB users can
read the files easily without having to specify a locale in which to interpret date and time
data.

Write Dates in Other Languages


Specify an appropriate format for text representing dates and times when you use the
char or cellstr functions. For example, convert two datetime values to a cell array of
character vectors using cellstr. Specify the format and the locale to represent the day,
month, and year of each datetime value as text.

t = [datetime('today');datetime('tomorrow')]

t = 2x1 datetime array
13-Apr-2019

7 Dates and Time

Free download pdf