stringToPosix: Convert a Time String to a POSIXct Object

Description Usage Arguments Examples

View source: R/convert.R

Description

Convert a time string to a POSIXct object. Allow for different possible timestamp formats.

Usage

1
2
3
4
5
stringToPosix(
  x,
  formats = c("%Y-%m-%d %H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d"),
  ...
)

Arguments

x

character vector of length one representing a timestamp

formats

vector of allowed time formats (using %-placeholders)

...

arguments passed to hsToPosix

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
stringToPosix("2016-05-26")
stringToPosix("2016-05-26 12:00")
  
# additional arguments passed to hsToPosix
stringToPosix("2016-05-26 12:00:33", tzone = "ETC/Gmt-1")
  
# lt = TRUE -> create POSIXlt instead of POSIXct
lt1 <- stringToPosix("2016-05-26 17:00", lt = TRUE)
lt2 <- stringToPosix("2016-05-26 17:00", lt = TRUE, tz = "Europe/Berlin")
  
lt1$hour
lt1$isdst # normal time (is daylight saving time = FALSE)
lt2$isdst # summer time (is daylight saving time = TRUE)

KWB-R/kwb.datetime documentation built on July 9, 2021, 10:28 p.m.