datetime - Date conversion from POSIXct to Date in R -


can tell me why r give such outcome below:

> as.posixct("2013-01-01 08:00") [1] "2013-01-01 08:00:00 hkt" > as.date(as.posixct("2013-01-01 08:00")) [1] "2013-01-01" > as.posixct("2013-01-01 07:00") [1] "2013-01-01 07:00:00 hkt" > as.date(as.posixct("2013-01-01 07:00")) [1] "2012-12-31" 

shouldn't 2013-01-01 after converting posixct date 2013-01-01 07:00, there way change cutoff 08:00 00:00?

update #1

i found following can fix problem, in less neat way

> as.date(as.character(as.posixct("2013-01-01 07:00"))) [1] "2013-01-01" 

the problem here timezones - can see you're in "hkt". try:

as.date(as.posixct("2013-01-01 07:00", 'gmt')) [1] "2013-01-01" 

from ?as.date(): ["posixct" is] converted days ignoring time after midnight in representation of time in specified timezone, default utc


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -