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

Change php variable from jquery value using ajax (same page) -

How can I fetch data from a web server in an android application? -

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