您的位置:首页 > 编程语言 > MATLAB

date and time information matlab

2012-02-07 18:04 399 查看

Date and Time Functions

This table shows what information is available in MATLAB withrespect to dates and times and which function provides this information.The sections that follow the table provide more information on howto use the different date and time formats.

Date and Time InformationOutput FormatFunction toUse
Current date and timeDate numbernow
Date vectorclock
Date stringdatestr(now)
Current dateDate numberdatenum(date)
Date vectordatevec(date)
Date stringdate
Day of week for given dateFull day name, abbreviated name, or day number in week (1-7)weekday
Last day of given month(s)Vector of one or more dayseomday
Date with modified fieldDate numberaddtodate
Calendar for given month6-by-7 matrix of dayscalendar

Date String Tables

Symbolic Identifiers for Individual Fields

The following table shows:

The nine fields of a date string (left column)

Ways to format each field

Example output for each field

Assigned character-based field identifiers

FieldStringFormatExample of OutputField Identifier
Quarter yearLetter Q and 1 digitQ4'QQ'
Year4 digits2007'yyyy'
2 digits07'yy'
MonthFull nameDecember'mmmm'
First 3 lettersDec'mmm'
2 digits12'mm'
First letterD'm'
DayFull nameTuesday'dddd'
First 3 lettersTue'ddd'
2 digits20'dd'
First letterT'd'
Hour2 digits16'HH'
Minute2 digits02'MM'
Second2 digits54'SS'
MillisecondDecimal point and 3 digits.057'FFF'
12-hour periodAM or PMPM'AM' or 'PM'
Notes Concerning Usage. Here are a few points toremember when using the symbolic identifiers:

MATLAB interpretsthe field specifiers in this table according to your computer's languagesetting and the current MATLAB language setting.

In a field specifier string, you cannot specify any field morethan once. For example, you cannot use
'yy-mmm-dd-m' becauseit has two month identifiers. The one exception to this is that youcan combine one instance of
dd with one instanceof any of the other day identifiers:

ds = datestr(now, 'dddd  mmm dd yyyy')
ds =
Wednesday  Jun 30 2010

You only can use QQ (quarter of the year)alone or with a year specifier.

Numeric Identifiers for Predefined Formats

The following table shows numeric identifiers you can use toinclude certain field and format combinations in a date string.

Date String FormatsExample of OutputIdentifier to Use
'dd-mmm-yyyy HH:MM:SS'01-Mar-2000 15:45:170
'dd-mmm-yyyy'01-Mar-20001
'mm/dd/yy'03/01/002
'mmm'Mar3
'm'M4
'mm'035
'mm/dd'03/016
'dd'017
'ddd'Wed8
'd'W9
'yyyy'200010
'yy'0011
'mmmyy'Mar0012
'HH:MM:SS'15:45:1713
'HH:MM:SS PM'3:45:17 PM14
'HH:MM'15:4515
'HH:MM PM'3:45 PM16
'QQ-YY'Q1-0117
'QQ'Q118
'dd/mm'01/0319
'dd/mm/yy'01/03/0020
'mmm.dd,yyyy HH:MM:SS'Mar.01,2000 15:45:1721
'mmm.dd,yyyy'Mar.01,200022
'mm/dd/yyyy'03/01/200023
'dd/mm/yyyy'01/03/200024
'yy/mm/dd'00/03/0125
'yyyy/mm/dd'2000/03/0126
'QQ-YYYY'Q1-200127
'mmmyyyy'Mar200028
'yyyy-mm-dd' (ISO 8601)2000-03-0129
'yyyymmddTHHMMSS' (ISO 8601)20000301T15451730
'yyyy-mm-dd HH:MM:SS'2000-03-01 15:45:1731
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: