1.now 返回当前的日期值(这个数的整数部分表示从公元0年1月1日到该日的天数,小数部分则表示具体的时刻)
eg.
t=now
t =7.3354e+005
2.datestr 日期转换成字符形式
调用格式 datestr(date,dateform) date为要转换的日期值,dateform为日期格式参数(具体参数值可通过 help datestr查看帮助)
dateform参数说明
Table 1: Standard MATLAB Date format definitions
Number String Example
===========================================================================
0 'dd-mmm-yyyy HH:MM:SS' 01-Mar-2000 15:45:17
1 'dd-mmm-yyyy' 01-Mar-2000
2 'mm/dd/yy' 03/01/00
3 'mmm' Mar
4 'm' M
5 'mm' 03
6 'mm/dd' 03/01
7 'dd' 01
8 'ddd' Wed
9 'd' W
10 'yyyy' 2000
11 'yy' 00
12 'mmmyy' Mar00
13 'HH:MM:SS' 15:45:17
14 'HH:MM:SS PM' 3:45:17 PM
15 'HH:MM' 15:45
16 'HH:MM PM' 3:45 PM
17 'QQ-YY' Q1-96
18 'QQ' Q1
19 'dd/mm' 01/03
20 'dd/mm/yy' 01/03/00
21 'mmm.dd,yyyy HH:MM:SS' Mar.01,2000 15:45:17
22 'mmm.dd,yyyy' Mar.01,2000
23 'mm/dd/yyyy' 03/01/2000
24 'dd/mm/yyyy' 01/03/2000
25 'yy/mm/dd' 00/03/01
26 'yyyy/mm/dd' 2000/03/01
27 'QQ-YYYY' Q1-1996
28 'mmmyyyy' Mar2000
29 (ISO 8601) 'yyyy-mm-dd' 2000-03-01
30 (ISO 8601) 'yyyymmddTHHMMSS' 20000301T154517
31 'yyyy-mm-dd HH:MM:SS' 2000-03-01 15:45:17
Table 2: Free-form date format symbols
Symbol Interpretation of format symbol
===========================================================================
yyyy full year, e.g. 1990, 2000, 2002
yy partial year, e.g. 90, 00, 02
mmmm full name of the month, according to the calendar locale, e.g.
"March", "April" in the UK and USA English locales.
mmm first three letters of the month, according to the calendar
locale, e.g. "Mar", "Apr" in the UK and USA English locales.
mm numeric month of year, padded with leading zeros, e.g. ../03/..
or ../12/..
m capitalized first letter of the month, according to the
calendar locale; for backwards compatibility.
dddd full name of the weekday, according to the calendar locale, e.g.
"Monday", "Tuesday", for the UK and USA calendar locales.
ddd first three letters of the weekday, according to the calendar
locale, e.g. "Mon", "Tue", for the UK and USA calendar locales.
dd numeric day of the month, padded with leading zeros, e.g.
05/../.. or 20/../..
d capitalized first letter of the weekday; for backwards
compatibility
HH hour of the day, according to the time format. In case the time
format AM | PM is set, HH does not pad with leading zeros. In
case AM | PM is not set, display the hour of the day, padded
with leading zeros. e.g 10:20 PM, which is equivalent to 22:20;
9:00 AM, which is equivalent to 09:00.
MM minutes of the hour, padded with leading zeros, e.g. 10:15,
10:05, 10:05 AM.
SS second of the minute, padded with leading zeros, e.g. 10:15:30,
10:05:30, 10:05:30 AM.
FFF milliseconds field, padded with leading zeros, e.g.
10:15:30.015.
PM set the time format as time of morning or time of afternoon. AM
or PM is appended to the date string, as appropriate.
eg.
>> t=now;datestr(t,0)
ans =09-May-2008 21:07:23
3.date将字符串转换成日期值
调用语法:date(year,month,day)
datenum(year,month,day,hour,minute,second)
eg.
>> t=now;datestr(t,0)
ans =09-May-2008 21:07:23
>> datenum(ans)
ans =7.3354e+005
>>
4.datevec将datestr中指定的格式日期字符转换成包含日期分量的数值向量
eg.
>>c=datevec('09-May-2008 21:07:23')
c = 2008 5 9 21 7 23
5.weekday 可从一个日期值或字符串中找出具体的日子和星期。
eg.
>> [d,w]=weekday( 7.3354e+005)d = 2
w =Mon>>[d,w]=weekday('21-Dec-2008')d = 1
w =Sun6.eomday 返回任何一个月最后一天是几号
调用语法:eomday(year,month) 因为闰年的存在故需要year这个参数。
eg.
>> eomday(2008,2)
ans = 29
>> eomday(2007,2)
ans = 28
7.calendar 生成指定月份的日历。
eg
>> calendar(date)
May 2008
S M Tu W Th F S
0 0 0 0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
0 0 0 0 0 0 0
>> calendar(2008,5)
May 2008
S M Tu W Th F S
0 0 0 0 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
0 0 0 0 0 0 0>>
补充:date返回当天日期的字符串
eg.
>> dateans =09-May-20088.tic ,toc 两个结合使用可计算一组matlab操作指令的执行所需时间
eg.
>> tic; plot(rand(500,5));toc
Elapsed time is 0.078000 seconds.
另外Matlab还提供了cputime和etime(具体使用方法可看帮助文档),用来计算一次运算所占cpu时间.
eg.
>>t0=cputime;myoperation;cputime-t0
ans=0.1400
>>t1=clock;myoperation;etime(clock,t1)
ans=11.2800
注:myoperation为用户自定义脚本文件
>> t0=cputimet0 = 53.8125
>> t1=cputimet1 = 54.0313
>> deltaT=t1-t0
deltaT = 0.2188 >> t1=clockt1 =1.0e+003 * 2.0080 0.0050 0.0090 0.0210 0.0460 0.0254>> deltaT=etime(t1,t0)deltaT = 9.9060>> 9.datetick 设一个坐标为时间标签eg. >> t=(1900:10:1990)'; >> p=[100 200 150 350 200 400 500 100 30 120]; >> plot(datenum(t,1,1),p); >> datetick('x','yyyy') >> title('test time tip')