ID EN
Date & Time

strptime

R Base 3.6.2 🇮🇩 Bahasa Indonesia

Berfungsi untuk mengkonversi antara representasi karakter dan objek kelas "POSIXlt" dan "POSIXct" yang mewakili tanggal dan waktu kalender.

Syntax

R
# S3 method for POSIXct
format(x, format = "", tz = "", usetz = FALSE, …)
# S3 method for POSIXlt
format(x, format = "", usetz = FALSE, &#8230;)<p></p><p># S3 method for POSIXt
as.character(x, &#8230;)</p><p>strftime(x, format = "", tz = "", usetz = FALSE, &#8230;)
strptime(x, format, tz = "")</p>

Arguments

Parameter Deskripsi
x An object to be converted: a character vector for strptime, an object which can be converted to "POSIXlt" for strftime.
tz A character string specifying the time zone to be used for the conversion. System-specific (see as.POSIXlt), but "" is the current time zone, and "GMT" is UTC. Invalid values are most commonly treated as UTC, on some platforms with a warning.
format A character string. The default for the format methods is "%Y-%m-%d %H:%M:%S" if any element has a time component which is not midnight, and "%Y-%m-%d" otherwise. If options("digits.secs") is set, up to the specified number of digits will be printed for seconds.
&#8230; Further arguments to be passed from or to other methods.
usetz logical. Should the time zone abbreviation be appended to the output? This is used in printing times, and more reliable than using "%Z".

Return Value

Metode format dan strftime mengembalikan vektor karakter yang mewakili waktu. Waktu NA dikembalikan sebagai NA_character_. Elemen dibatasi hingga 256 byte, ditambah singkatan zona waktu jika usetz benar. (Pada platform yang dikenal, string yang lebih panjang dipotong pada 255 atau 256 byte, tetapi ini tidak dijamin oleh standar C99.) strptime mengubah representasi karakter menjadi objek kelas "POSIXlt". Zona waktu digunakan untuk menyetel komponen isdst dan menyetel atribut "tzone" jika tz != "".

Details

Metode format dan as.character serta strftime mengonversi objek dari kelas "POSIXlt" dan "POSIXct" menjadi vektor karakter. strptime mengonversi vektor karakter ke kelas "POSIXlt": inputnya x pertama kali dikonversi oleh as.character. Setiap string masukan diproses sejauh diperlukan untuk format yang ditentukan: karakter tambahan apa pun akan diabaikan. strftime adalah pembungkus untuk format.POSIXlt, dan strftime serta format.POSIXct terlebih dahulu dikonversi ke kelas "POSIXlt" dengan memanggil as.POSIXlt (jadi keduanya juga berfungsi untuk kelas "Tanggal"). Perhatikan bahwa hanya konversi tersebut yang bergantung pada zona waktu. Aturan daur ulang vektor yang biasa diterapkan pada x dan format sehingga jawabannya adalah panjang dari vektor-vektor tersebut. Konversi spesifik lokal ke dan dari string karakter digunakan jika diperlukan dan tersedia. Hal ini mempengaruhi

Contoh

Example
R
# NOT RUN {
## locale-specific version of date()
format(Sys.time(), "%a %b %d %X %Y %Z")

## time to sub-second accuracy (if supported by the OS)
format(Sys.time(), "%H:%M:%OS3")

## read in date info in format 'ddmmmyyyy'
## This will give NA(s) in some non-English locales; setting the C locale
## as in the commented lines will overcome this on most systems.
## lct <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
x <- c("1jan1960", "2jan1960", "31mar1960", "30jul1960")
z <- strptime(x, "%d%b%Y")
## Sys.setlocale("LC_TIME", lct)
z

## read in date/time info in format 'm/d/y h:m:s'
dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92")
times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26")
x <- paste(dates, times)
strptime(x, "%m/%d/%y %H:%M:%S")

## time with fractional seconds
z <- strptime("20/2/06 11:16:16.683", "%d/%m/%y %H:%M:%OS")
z # prints without fractional seconds
op <- options(digits.secs = 3)
z
options(op)

## time zone names are not portable, but 'EST5EDT' comes pretty close.
(x <- strptime(c("2006-01-08 10:07:52", "2006-08-07 19:33:02"),
               "%Y-%m-%d %H:%M:%S", tz = "EST5EDT"))
attr(x, "tzone")

## An RFC 5322 header (Eastern Canada, during DST)
## In a non-English locale the commented lines may be needed.
## prev <- Sys.getlocale("LC_TIME"); Sys.setlocale("LC_TIME", "C")
strptime("Tue, 23 Mar 2010 14:36:38 -0400", "%a, %d %b %Y %H:%M:%S %z")
## Sys.setlocale("LC_TIME", prev)

## Make sure you know what the abbreviated names are for you if you wish
## to use them for input (they are matched case-insensitively):
format(seq.Date(as.Date('1978-01-01'), by = 'day', len = 7), "%a")
format(seq.Date(as.Date('2000-01-01'), by = 'month', len = 12), "%b")
# }

See Also

DateTimeClasses for details of the date-time classes; locales to query or set a locale. Your system's help page on strftime to see how to specify their formats. (On some systems including Windows strftime is replaced by more comprehensive internal code.)