简体   繁体   中英

R POSIXct and as.Date

I have a date and time value which I'm using POSIXct to store in a variable. and when I use as.Date the date is different - why ?

x<-as.POSIXct("2012-02-25 19:00:00")
as.Date(x)
 [1] "2012-02-**26**"

Why is it incrementing day by 1?

By simply using x<-as.POSIXct("2012-02-25 19:00:00") you will be setting the time zone, tz , to your current systems time zone, EST.

However when you use as.Date without declaring a time zone it will default to GMT. GMT is 5 hours ahead of EST so 25/02/2012 19:00 is 00:00 26/02/2012.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM