Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
19
Добавлен:
09.02.2015
Размер:
109.06 Кб
Скачать

matlab\timefun – Функции времени и даты

Current date and time

<now> - Current date and time as date number.

NOW Current date and time as date number.

T = NOW returns the current date and time as a serial date

number.

FLOOR(NOW) is the current date and REM(NOW,1) is the current time.

DATESTR(NOW) is the current date and time as a string.

See also date, datenum, datestr, clock.

Reference page in Help browser

doc now

<date> - Current date as date string.

DATE Current date as date string.

S = DATE returns a string containing the date in dd-mmm-yyyy format.

See also now, clock, datenum.

Reference page in Help browser

doc date

<clock> - Current date and time as date vector.

CLOCK Current date and time as date vector.

C = CLOCK returns a six element date vector containing the current time

and date in decimal form:

[year month day hour minute seconds]

The sixth element of the date vector output (seconds) is accurate to

several digits beyond the decimal point. FIX(CLOCK) rounds to integer

display format.

Note: When timing the duration of an event, use the TIC and TOC

functions instead of CLOCK or ETIME. These latter two functions are

based on the system time which can be adjusted periodically by the

operating system and thus might not be reliable in time comparison

operations.

See also datevec, datenum, now, etime, tic, toc, cputime.

Reference page in Help browser

doc clock

Basic functions

<datenum> - Serial date number.

DATENUM Serial date number.

N = DATENUM(V) converts one or more date vectors V into serial date

numbers N. Input V can be an M-by-6 or M-by-3 matrix containing M full

or partial date vectors respectively. DATENUM returns a column vector

of M date numbers.

A date vector contains six elements, specifying year, month, day, hour,

minute, and second. A partial date vector has three elements, specifying

year, month, and day. Each element of V must be a positive double

precision number. A serial date number of 1 corresponds to Jan-1-0000.

The year 0000 is merely a reference point and is not intended to be

Interpreted as a real year.

N = DATENUM(S,F) converts one or more date strings S to serial date

numbers N using format string F. S can be a character array where each

row corresponds to one date string, or one dimensional cell array of

strings. DATENUM returns a column vector of M date numbers, where M is the number of strings in S.

All of the date strings in S must have the same format F, which must be

composed of date format symbols according to Table 2 in DATESTR help.

Formats with 'Q' are not accepted by DATENUM.

Certain formats may not contain enough information to compute a date

number. In those cases, hours, minutes, and seconds default to 0, days

default to 1, months default to January, and years default to the

current year. Date strings with two character years are interpreted to

be within the 100 years centered around the current year.

N = DATENUM(S,F,P) or N = DATENUM(S,P,F) uses the specified format F and the pivot year P to determine the date number N, given the date string S. The pivot year is the starting year of the 100-year range in which a two-character year resides. The default pivot year is the current year minus 50 years.

N = DATENUM(Y,MO,D) and N = DATENUM([Y,MO,D]) return the serial date numbers for corresponding elements of the Y,MO,D (year,month,day)

arrays. Y, MO, and D must be arrays of the same size (or any can be a

scalar).

N = DATENUM(Y,MO,D,H,MI,S) and N =DATENUM([Y,MO,D,H,MI,S]) return the serial date numbers for corresponding elements of the Y,MO,D,H,MI,S (year,month,day,hour,minute,second) arrays. The six arguments must be arrays of the same size (or any can be a scalar).

N = DATENUM(S) converts the string or date vector (as defined by

DATEVEC) S into a serial date number. If S is a string, it must be in

one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.

This calling syntax is provided for backward compatibility, and is

significantly slower than the syntax which specifies the format string.

If the format is known, the N = DATENUM(S,F) syntax should be used.

N = DATENUM(S,P) converts the date string S, using pivot year P. If the

format is known, the N = DATENUM(S,F,P) or N = DATENUM(S,P,F) syntax should be used.

Note: The vectorized calling syntax can offer significant performance

improvement for large arrays.

Examples:

n = datenum('19-May-2000') returns n = 730625.

n = datenum(2001,12,19) returns n = 731204.

n = datenum(2001,12,19,18,0,0) returns n = 731204.75.

n = datenum('19.05.2000','dd.mm.yyyy') returns n = 730625.

See also now, datestr, datevec, datetick.

Reference page in Help browser

doc datenum

<datestr> - String representation of date.

DATESTR String representation of date.

S = DATESTR(V) converts one or more date vectors V to date strings S.

Input V must be an M-by-6 matrix containing M full (six-element) date

vectors. Each element of V must be a positive double-precision number.

DATESTR returns a column vector of M date strings, where M is the total

number of date vectors in V.

S = DATESTR(N) converts one or more serial date numbers N to date

strings S. Input argument N can be a scalar, vector, or

multidimensional array of positive double-precision numbers. DATESTR

returns a column vector of M date strings, where M is the total number

of date numbers in N.

S = DATESTR(D, F) converts one or more date vectors, serial date

numbers, or date strings D into the same number of date strings S.

Input argument F is a format number or string that determines the

format of the date string output. Valid values for F are given in Table

1, below. Input F may also contain a free-form date format string

consisting of format tokens as shown in Table 2, below.

Date strings with 2-character years are interpreted to be within the

100 years centered around the current year.

S = DATESTR(S1, F, P) converts date string S1 to date string S,

applying format F to the output string, and using pivot year P as the

starting year of the 100-year range in which a two-character year

resides. The default pivot year is the current year minus 50 years.

F = -1 uses the default format.

S = DATESTR(...,'local') returns the string in a localized format. The

default (which can be called with 'en_US') is US English. This argument

must come last in the argument sequence.

Note: The vectorized calling syntax can offer significant performance

improvement for large arrays.

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.

Examples:

DATESTR(now) returns '24-Jan-2003 11:58:15' for that particular date,

on an US English locale DATESTR(now,2) returns 01/24/03, the same as

for DATESTR(now,'mm/dd/yy') DATESTR(now,'dd.mm.yyyy') returns

24.01.2003 To convert a non-standard date form into a standard MATLAB

dateform, first convert the non-standard date form to a date number,

using DATENUM, for example,

DATESTR(DATENUM('24.01.2003','dd.mm.yyyy'),2) returns 01/24/03.

See also date, datenum, datevec, datetick.

Reference page in Help browser

doc datestr

<datevec> - Date components.

DATEVEC Date components.

V = DATEVEC(N) converts one or more date numbers N to date vectors V. N can be a scalar, vector, or multidimensional array of positive date numbers. DATEVEC returns an M-by-6 matrix containing M date vectors, where M is the total number of date numbers in N.

V = DATEVEC(S,F) converts one or more date strings S to date vectors

V using format string F to interpret the date strings in S. S can be a

cell array of strings or a character array where each row corresponds

to one date string. All of the date strings in S must have the same

format which must be composed of date format symbols according to

Table 2 in DATESTR help. Formats with 'Q' are not accepted by DATEVEC.

DATEVEC returns an M-by-6 matrix of date vectors, where M is the number of date strings in S.

Certain formats may not contain enough information to compute a date

vector. In those cases, hours, minutes, and seconds default to 0, days

default to 1, months default to January, and years default to the

current year. Date strings with two character years are interpreted to

be within the 100 years centered around the current year.

V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F) converts the date string S to a date vector V, using the pivot year P and the date format F. The pivot year is the starting year of the 100-year range in which a two-character year resides. The default pivot year is the current year minus 50 years.

[Y,MO,D,H,MI,S] = DATEVEC(...) takes any of the two syntaxes shown

above and returns the components of the date vector as individual

variables.

V = DATEVEC(S) converts date string S to date vector V. S must be in

one of the date formats 0,1,2,6,13,14,15,16,23 as defined by DATESTR.

This calling syntax is provided for backward compatibility, and is

significantly slower than the syntax which specifies the format string.

If the format is known, the V = DATEVEC(S,F) syntax should be used.

V = DATEVEC(S,P) converts the date string S using pivot year P.

If the format is known, the V = DATEVEC(S,F,P) or V = DATEVEC(S,P,F)

syntax should be used.

Note 1: If more than one input argument is used, the first argument

must be a date string or array of date strings.

Note 2: The vectorized calling syntax can offer significant performance

improvement for large arrays.

Examples

d = '12/24/1984';

t = 725000.00;

c = datevec(d) or c = datevec(t) produce c = [1984 12 24 0 0 0].

[y,m,d,h,mi,s] = datevec(d) returns y=1984, m=12, d=24, h=0, mi=0, s=0.

c = datevec('5/6/03') produces c = [2003 5 6 0 0 0] until 2054.

c = datevec('5/6/03',1900) produces c = [1903 5 6 0 0 0].

c = datevec('19.05.2000','dd.mm.yyyy') produces c = [2000 5 19 0 0 0].

See also datenum, datestr, clock, datetick.

Reference page in Help browser

doc datevec

Соседние файлы в папке Библиотеки Matlab