Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Consider a string in the format

test <- "YYYY-MM-DDT00:00:00.000-08:00"

My goal is to convert those strings to POSIXct format so that I can plot the data. my initial thought was to use

as.POSIXct(test)

...but that seems to truncate the datetime to just date. Any thoughts? The help info for as.POSIXct seems to imply that the input should be date and time separated by a space, not by a "T". Is this my issue?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
873 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to specify a format for your conversion. Take a read of ?strptime to see all of the options for date formats.

#YYYY-MM-DDT00:00:00.000-08:00
test <- "2013-12-25T04:32:16.500-08:00"
z <- as.POSIXct(test,format="%Y-%m-%dT%H:%M:%OS")
op <- options(digits.secs = 3)
z
#[1] "2013-12-25 04:32:16.5 EST"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...