lubritation的格式日期

发布于 2025-02-11 04:32:33 字数 533 浏览 3 评论 0原文

我的输入数据格式为角色,看起来像是

"2020-07-10T00:00:00"

我尝试过的

library(lubridate)
mdy_hms("2020-07-10T00:00:00", format='%Y-%m-%dT%H:%M:%S', tz=Sys.timezone())

,但是我得到了

[1] Na Na 警告消息: 所有格式都无法解析。找不到格式。

我尝试了更多的flexibel方法parse_date_time(),但是如果没有运气,

parse_date_time("2020-07-10T00:00:00", '%Y-%m-%dT%H:%M:%S', tz=Sys.timezone())

我该如何将此日期转换为“ 2020-07-10T00:00:00:00:00”:r识别的日期?注意:我真的对时间不感兴趣,只有日期!

My input data, formatted as character, looks like this

"2020-07-10T00:00:00"

I tried

library(lubridate)
mdy_hms("2020-07-10T00:00:00", format='%Y-%m-%dT%H:%M:%S', tz=Sys.timezone())

But I get

[1] NA NA
Warning message:
All formats failed to parse. No formats found.

I tried the more flexibel approach parse_date_time(), but without luck

parse_date_time("2020-07-10T00:00:00", '%Y-%m-%dT%H:%M:%S', tz=Sys.timezone())

How can I convert this date "2020-07-10T00:00:00" to a date R recognizes? Note: I am not interested in the time really, only the date!

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

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

发布评论

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

评论(2

野心澎湃 2025-02-18 04:32:33

为什么不只是

as.Date("2020-07-10T00:00:00")
# [1] "2020-07-10"

有趣的事实:

as.Date("2020-07-101sddT00:1sdafsdfsdf0:00sdfzsdfsdfsdf")
# [1] "2020-07-10"

Why not just

as.Date("2020-07-10T00:00:00")
# [1] "2020-07-10"

Fun fact:

as.Date("2020-07-101sddT00:1sdafsdfsdf0:00sdfzsdfsdfsdf")
# [1] "2020-07-10"
2025-02-18 04:32:33

假设07是7月的月份,而第10个月是第10个月:

x <- "2020-07-10T00:00:00"
ymd_hms(x, tz = Sys.timezone())

> [1] "2020-07-10 AEST"

如果以年度为单位,则将YMD换成YDM。

希望这有帮助!

Assuming that the 07 is the month of July, and the 10 is the 10th:

x <- "2020-07-10T00:00:00"
ymd_hms(x, tz = Sys.timezone())

> [1] "2020-07-10 AEST"

If it's in format year-day-month, swap the ymd for ydm.

Hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文