MATLAB——时间,日期及显示格式

一、日期和时间

1.生成指定格式日期和时间

技术分享

 

标准日期格式

技术分享

技术分享

2.获取当前时间的数值

>> datestr(now,31)

ans =

2017-09-11 19:56:26
>> datestr(now,yyyy-mm-dd HH:MM:SS)

ans =

2017-09-11 19:58:28



>> clock

ans =

   1.0e+03 *

    2.0170    0.0090    0.0110    0.0200    0.0030    0.0264

>> datestr(now,HH:MM:SS)

ans =

20:05:07

>> format short g
>> clock

ans =

         2017            9           11           20            5        42.98

>> now=fix(clock)

now =

        2017           9          11          20           9          16

上述转化为向量形式,可以随意调用年月日时分秒

3.其他时间和日期函数或命令

 

>> date

ans =

11-Sep-2017

 

从公元0年到现在的天数

>> n=datenum(now)

n =

   7.3695e+05

>> fix(n)

ans =

      736949
>> today

ans =

      736949

两次时间差(测试函数运行时间的函数)

>> t0=clock

t0 =

         2017            9           11           20           27        56.81

>> etime(clock,t0)

ans =

         18.8

>> t1=clock

t1 =

         2017            9           11           20           28       33.745

>> etime(t1,t0)

ans =

       36.935

利用占用CPU时间差,来进行时间差计算

>> t=cputime;
>> T=cputime-t

T =

       0.3276

tic/toc

>> tic%开始计时
>> toc%结束计时
时间已过 1.945333 秒。

星期值

>> weekday(today)

ans =

     2
>> [a,b]=weekday(today)

a =

     2


b =

Mon

>> [a,b]=weekday(today,long)

a =

     2


b =

Monday

某月的天数

eomday(2017,9)

ans =

    30

某年的天数

>> yeardays(2017)

ans =

   365
 
月份表
>> calendar Sep 2017 S M Tu W Th F S 0 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 0 0 0 0 0 0 0
>> calendar(2017,10)
                   Oct 2017
     S     M    Tu     W    Th     F     S
     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     0     0     0     0



 

 

 

 

文章来自:http://www.cnblogs.com/ruo-li-suo-yi/p/7507063.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3