Date conversion from POSIXct to Date in R

前端 未结 3 756
野性不改
野性不改 2020-11-27 04:39

can anyone 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          


        
3条回答
  •  渐次进展
    2020-11-27 04:52

    The problem here is timezones - you 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 to days by ignoring the time after midnight in the representation of the time in specified timezone, default UTC

提交回复
热议问题