Computes and returns values for all date and time fields.
Usage
stri_datetime_fields(time, tz = attr(time, "tzone"), locale = NULL)Arguments
- time
an object of class
POSIXct(as.POSIXctwill be called on character vectors and objects of classPOSIXlt,Date, andfactor)- tz
NULLor''for the default time zone or a single string with time zone identifier, seestri_timezone_list- locale
NULLor''for the current default locale, or a single string with a locale identifier; a non-Gregorian calendar may be specified by setting@calendar=namekeyword
Value
Returns a data frame with the following columns:
Year (0 is 1BC, -1 is 2BC, etc.)
Month (1-based, i.e., 1 stands for the first month, e.g., January; note that the number of months depends on the selected calendar, see
stri_datetime_symbols)Day
Hour (24-h clock)
Minute
Second
Millisecond
WeekOfYear (this is locale-dependent)
WeekOfMonth (this is locale-dependent)
DayOfYear
DayOfWeek (1-based, 1 denotes Sunday; see
stri_datetime_symbols)Hour12 (12-h clock)
AmPm (see
stri_datetime_symbols)Era (see
stri_datetime_symbols)
See also
The official online manual of stringi at https://stringi.gagolewski.com/
Gagolewski M., stringi: Fast and portable character string processing in R, Journal of Statistical Software 103(2), 2022, 1-59, doi:10.18637/jss.v103.i02
Other datetime:
stri_datetime_add(),
stri_datetime_create(),
stri_datetime_format(),
stri_datetime_fstr(),
stri_datetime_now(),
stri_datetime_symbols(),
stri_timezone_get(),
stri_timezone_info(),
stri_timezone_list()
Author
Marek Gagolewski and other contributors
Examples
stri_datetime_fields(stri_datetime_now())
#> Year Month Day Hour Minute Second Millisecond WeekOfYear WeekOfMonth
#> 1 2025 11 25 19 56 32 725 48 5
#> DayOfYear DayOfWeek Hour12 AmPm Era
#> 1 329 3 7 2 2
stri_datetime_fields(stri_datetime_now(), locale='@calendar=hebrew')
#> Year Month Day Hour Minute Second Millisecond WeekOfYear WeekOfMonth
#> 1 5786 3 5 19 56 32 728 10 2
#> DayOfYear DayOfWeek Hour12 AmPm Era
#> 1 64 3 7 2 1
stri_datetime_symbols(locale='@calendar=hebrew')$Month[
stri_datetime_fields(stri_datetime_now(), locale='@calendar=hebrew')$Month
]
#> [1] "Kislev"