无法格式化 POSIXct 数据以摆脱 EDT/EST 格式

发布于 2025-01-17 15:01:18 字数 437 浏览 4 评论 0原文

我有一个大数据集,有许多不同的日期, 我想将它们转换为posixct,但不在乎时间,我所需要的只是在日期之间格式化相同的时间。

例如,我的原始日期格式

2019-03-08 
2019-03-12 
2018-10-30 
2018-11-04 

使用代码data $ newdate< - as.posixct(data $ date,tz =“ utc”) 变成

2019-03-08 19:00:00 EST
2019-03-12 20:00:00 EDT
2018-10-30 20:00:00 EDT
2018-11-04 19:00:00 EST

我知道,由此产生的格式的时代在技术上是相同的,但是我也需要这样的格式,但是我不知道如何。我应该使用的时区与UTC不同吗?

I have a large dataset with many different dates,
I want to convert them to POSIXct but do not care about times, all I need is for the time to be formatted identical between dates.

E.g. my original date format

2019-03-08 
2019-03-12 
2018-10-30 
2018-11-04 

when using the code data$newdate <- as.POSIXct(data$date,tz="UTC")
becomes

2019-03-08 19:00:00 EST
2019-03-12 20:00:00 EDT
2018-10-30 20:00:00 EDT
2018-11-04 19:00:00 EST

I know that the times in the resulting format are technically identical, but I need them to be formatted as such too, but I can't figure out how. Is there a different timezone I should be using than UTC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泅人 2025-01-24 15:01:18

这可能会令人沮丧,因为在解析、转换和格式化时可能会输入时区数据。

> library(anytime)
> d <- c("2019-03-08","2019-03-12","2018-10-30","2018-11-04")
> anydate(d)
[1] "2019-03-08" "2019-03-12" "2018-10-30" "2018-11-04"
> anytime(d)
[1] "2019-03-08 CST" "2019-03-12 CDT" "2018-10-30 CDT" "2018-11-04 CDT"
>
> # force text format
> format(anytime(d), "%Y-%m-%d %H:%M:%S")
[1] "2019-03-08 00:00:00" "2019-03-12 00:00:00" "2018-10-30 00:00:00" 
[4] "2018-11-04 00:00:00"
> 
> # or use another helper from anytime
> iso8601(anytime(d))
[1] "2019-03-08T00:00:00" "2019-03-12T00:00:00" "2018-10-30T00:00:00" 
[4] "2018-11-04T00:00:00"
>

This can be frustrating as the timezone data can enter when parsing, converting, and formating.

> library(anytime)
> d <- c("2019-03-08","2019-03-12","2018-10-30","2018-11-04")
> anydate(d)
[1] "2019-03-08" "2019-03-12" "2018-10-30" "2018-11-04"
> anytime(d)
[1] "2019-03-08 CST" "2019-03-12 CDT" "2018-10-30 CDT" "2018-11-04 CDT"
>
> # force text format
> format(anytime(d), "%Y-%m-%d %H:%M:%S")
[1] "2019-03-08 00:00:00" "2019-03-12 00:00:00" "2018-10-30 00:00:00" 
[4] "2018-11-04 00:00:00"
> 
> # or use another helper from anytime
> iso8601(anytime(d))
[1] "2019-03-08T00:00:00" "2019-03-12T00:00:00" "2018-10-30T00:00:00" 
[4] "2018-11-04T00:00:00"
>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文