Format the given date/time according to the format f and return
the result in str.
date is a serial date number (see datenum) or a date vector
(see datevec). The value of date may also be a string or cell
array of strings.
f can be an integer which corresponds to one of the codes in the table below, or a date format string.
p is the year at the start of the century in which two-digit years are to be interpreted in. If not specified, it defaults to the current year minus 50.
For example, the date 730736.65149 (2000-09-07 15:38:09.0934) would be formatted as follows:
| Code | Format | Example |
|---|---|---|
| 0 | dd-mmm-yyyy HH:MM:SS | 07-Sep-2000 15:38:09 |
| 1 | dd-mmm-yyyy | 07-Sep-2000 |
| 2 | mm/dd/yy | 09/07/00 |
| 3 | mmm | Sep |
| 4 | m | S |
| 5 | mm | 09 |
| 6 | mm/dd | 09/07 |
| 7 | dd | 07 |
| 8 | ddd | Thu |
| 9 | d | T |
| 10 | yyyy | 2000 |
| 11 | yy | 00 |
| 12 | mmmyy | Sep00 |
| 13 | HH:MM:SS | 15:38:09 |
| 14 | HH:MM:SS PM | 3:38:09 PM |
| 15 | HH:MM | 15:38 |
| 16 | HH:MM PM | 3:38 PM |
| 17 | QQ-YY | Q3-00 |
| 18 | Q3 | |
| 19 | dd/mm | 07/09 |
| 20 | dd/mm/yy | 07/09/00 |
| 21 | mmm.dd,yyyy HH:MM:SS | Sep.07,2000 15:38:08 |
| 22 | mmm.dd,yyyy | Sep.07,2000 |
| 23 | mm/dd/yyyy | 09/07/2000 |
| 24 | dd/mm/yyyy | 07/09/2000 |
| 25 | yy/mm/dd | 00/09/07 |
| 26 | yyyy/mm/dd | 2000/09/07 |
| 27 | QQ-YYYY | Q3-2000 |
| 28 | mmmyyyy | Sep2000 |
| 29 | yyyy-mm-dd | 2000-09-07 |
| 30 | yyyymmddTHHMMSS | 20000907T153808 |
| 31 | yyyy-mm-dd HH:MM:SS | 2000-09-07 15:38:08 |
If f is a format string, the following symbols are recognized:
| Symbol | Meaning | Example |
|---|---|---|
| yyyy | Full year | 2005 |
| yy | Two-digit year | 05 |
| mmmm | Full month name | December |
| mmm | Abbreviated month name | Dec |
| mm | Numeric month number (padded with zeros) | 01, 08, 12 |
| m | First letter of month name (capitalized) | D |
| dddd | Full weekday name | Sunday |
| ddd | Abbreviated weekday name | Sun |
| dd | Numeric day of month (padded with zeros) | 11 |
| d | First letter of weekday name (capitalized) | S |
| HH | Hour of day, padded with zeros, | 09:00 |
| or padded with spaces if PM is set | 9:00 AM | |
| MM | Minute of hour (padded with zeros) | 10:05 |
| SS | Second of minute (padded with zeros) | 10:05:03 |
| FFF | Milliseconds of second (padded with zeros) | 10:05:03.012 |
| AM | Use 12-hour time format | 11:30 AM |
| PM | Use 12-hour time format | 11:30 PM |
If f is not specified or is -1, then use 0, 1 or 16, depending
on whether the date portion or the time portion of date is empty.
If p is nor specified, it defaults to the current year minus 50.
If a matrix or cell array of dates is given, a column vector of date strings is returned.
See also: datenum, datevec, date, now, clock.
The following code
## Current date and time in default format datestr (now ())
Produces the following output
ans = 02-Jan-2017 11:55:22
The following code
## Current date (integer portion of datenum) datestr (fix (now ()))
Produces the following output
ans = 02-Jan-2017
The following code
## Current time (fractional portion of datenum) datestr (rem (now (), 1))
Produces the following output
ans = 11:55 AM
Package: octave