| format | R Documentation |
tind Class and Character Vectorsformat method converts objects of tind class to character
vectors given format and locale information. strptind function
accepts character vector with time indices and parses to create object
of tind class.
## S3 method for class 'tind'
format(x, format, locale = NULL, ...)
strptind(x, format, locale = NULL, type = NULL, tz = NULL)
x |
an object to be converted, a character vector for |
format |
a character string or character vector determining string format(s) (see Details). |
locale |
a character value determining locale to be used for |
... |
(ignored) further arguments passed to or from other methods. |
type |
(optional) a character value determining time index type. |
tz |
(optional) a character value determining the time zone (the default
|
Names of accepted format specifiers except for %q are conformant
with those used by format.Date, format.Date
and strptime. Accepted specifiers are listed below:
%aAbbreviated weekday name.
%AWeekday name.
%bAbbreviated month name.
%BMonth name.
%dDay of month (01–31).
%eDay of month (1–31) with a leading space for a single-digit number.
%DAmerican/C99 date representation %m/%d/%y.
%FISO 8601 date %Y-%m-%d.
%gThe last two digits of the week-based year.
%GThe week-based year.
%HHour (00–23).
%IHour, 12-hour clock (1–12).
%pAM/PM indicator.
%jDay of year (001–366).
%mMonth (01–12).
%MMinute (00–59).
%nNewline.
%OS[n]Second with n (0–6) decimal places.
%OSSecond with up to 6 decimal places (automatically detected precision during parsing).
%q(Not supported by base R.) Quarter (1–4).
%RSame as %H:%M.
%SSecond (00–59), leap seconds are not accepted on input.
%tTab or whitespace.
%TSame as %H:%M:%S.
%uWeekday (1–7) with Monday as the first day in a week (ISO 8601).
%VWeek (01–53) as defined in ISO 8601.
%y2-digit year (00–99), values 00–68 are prefixed by 20 and 69–99 by 19.
%Y4-digit year (0–9999), 0 is allowed by ISO 8601.
%zSigned offset in hours and minutes from UTC, accepted
input formats are +-HHMM, +-HH,
+-HH:MM, and letter Z for UTC.
%ZTime zone abbreviation (also supported on input).
On very rare occasions (the need to use formats unsupported by strptind)
users will have to call strptime and then as.tind
method or perform some regex preprocessing before calling strptind.
type argument is optional as strptind automatically determines
index type from components. However, it can be set as a safeguard against format
misspecifications.
strptime returns an object of tind class, format
returns a character vector.
The following strptime specifiers (as well as some others)
are not supported (most often because they are locale specific or do not
comply with ISO 8601):
%cLocale-specific date and time.
%CCentury (00–99).
%hEquivalent to %b.
%r12-hour clock time using AM/PM indicator.
%UWeek of the year (US convention).
%wWeekday (0–6).
%WWeek of the year (UK convention).
%xLocale-specific date.
%XLocale-specific time.
parse_t for easier to use index parsing requiring
order specification only, calendar-names for information on locale settings.
## years
# four-digit year
(ti <- strptind(as.character(1998:2002), "%Y"))
format(ti, "%Y")
# two-digit year
(ti <- strptind(c("98", "99", "00", "01", "02"), "%y"))
format(ti, "%y")
# mixture of four-digit and two-digit years
strptind(c("1998", "1999", "00", "01", "02"), c("%Y", "%y"))
## quarters
(ti <- strptind(c("2020Q1", "2020Q2", "2020Q3", "2020Q4"), "%YQ%q"))
format(ti, "%YQ%q")
format(ti, "%Yq%q")
format(ti, "%Y.%q")
## months
(ti <- strptind(c("2020-03", "2020-06", "2020-09", "2020-12"), "%Y-%m"))
format(ti, "%Y-%m")
(ti <- strptind(c("03/20", "06/20", "09/20", "12/20"), "%m/%y"))
format(ti, "%m/%y")
format(ti, "%b '%y")
## weeks
(ti <- strptind(c("2020-W01", "2020-W05", "2020-W09", "2020-W13"), "%G-W%V"))
format(ti, "%G-W%V")
format(ti, "%G, week: %V")
strptind(c("2020, week: 13"), "%G, week: %V")
## dates
# ISO format
(ti <- strptind(c("2025-03-19", "2025-06-18", "2025-09-17", "2025-12-17"), "%F"))
format(ti, "%F")
strptind(c("2025-03-19", "2025-06-18", "2025-09-17", "2025-12-17"), "%Y-%m-%d")
format(ti, "%Y-%m-%d")
# US format
strptind(c("03/19/25", "06/18/25", "09/17/25", "12/17/25"), "%D")
format(ti, "%D")
strptind(c("03/19/25", "06/18/25", "09/17/25", "12/17/25"), "%m/%d/%y")
format(ti, "%m/%d/%y")
# European format
strptind(c("19.03.2025", "18.06.2025", "17.09.2025", "17.12.2025"), "%d.%m.%Y")
format(ti, "%d.%m.%Y")
# mixed formats
strptind(c("03/19/25", "06/18/25", "17.09.2025", "17.12.2025"),
c("%m/%d/%y", "%d.%m.%Y"))
strptind(c("03/19/25", "06/18/25", "2025-09-17", "2025-12-17"),
c("%D", "%F"))
## time of day
(ti <- strptind("13:03:34.534", "%H:%M:%OS"))
format(ti, "%H:%M:%OS3")
format(ti, "%H:%M:%OS2")
format(ti, "%H:%M:%OS1")
strptind("13:03:34", "%H:%M:%S")
format(ti, "%H:%M:%S")
strptind("13:03", "%H:%M")
format(ti, "%H:%M")
strptind("13", "%H")
format(ti, "%H")
strptind("01:03:44 pm", "%I:%M:%S %p")
format(ti, "%I:%M:%S %p")
strptind("1:03:44 pm", "%I:%M:%S %p")
strptind(c("1am", "1pm"), "%I%p")
## date-time
(ti <- strptind("2025-02-01 13:03:34.534", "%F %H:%M:%OS"))
format(ti, "%F %H:%M:%S")
format(ti, "%F %H:%M:%OS2")
format(ti, "%F %H:%M:%S%z")
format(ti, "%F %H:%M:%OS2 %Z")
strptind("02/01/25 01:03:34pm", "%D %I:%M:%OS%p")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.