date and time information matlab

本文详细介绍了MATLAB中与日期和时间相关的函数,包括获取当前日期和时间、日期格式转换以及如何使用不同的日期和时间格式。此外,还提供了日期字符串表格,展示如何通过符号标识符和预定义格式来格式化日期字符串。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值