从POSIXct转换为R中的日期 [英] Date conversion from POSIXct to Date in R

查看:134
本文介绍了从POSIXct转换为R中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我为什么R在下面给出这样的结果:

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 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"

转换 POSIXct 2013-01-01 c>到日期 2013-01-01 07:00 ,有没有办法更改截止从 08:00 00:00

Shouldn't it be 2013-01-01 after converting POSIXct to Date for 2013-01-01 07:00, is there any way to change the cutoff from 08:00 to 00:00?

我发现以下内容可以解决我的问题,但是在一个不太整洁的方式

I found the following can fix my problem, but in a less neat way

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


推荐答案

这里的问题是时区,你可以看到你在HKT 。尝试:

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"

?as.Date():[ POSIXct 被转换为天数,忽略午夜后的时间在指定时间内的时间时区,默认UTC

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

这篇关于从POSIXct转换为R中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆