R lubridate包日期时间创建忽略了午夜的时间 [英] R lubridate package date-time creation omits time at midnight

查看:71
本文介绍了R lubridate包日期时间创建忽略了午夜的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用lubridate包创建日期时间,并且尝试了以下值:

I am trying to create date-time using lubridate package, and I've tried the following values:

library(lubridate)
ymd_hms("2017-07-02 23:00:00")
[1] "2017-07-02 23:00:00 UTC"
ymd_hms("2017-07-02 00:00:00")
[1] "2017-07-02 UTC"

似乎如果您在午夜00:00:00键入时间,则ymd_hms()方法将忽略时间值,结果将成为日期.有什么办法可以在结果中显示00:00:00? 非常感谢!

It seems that if you type the time at midnight, 00:00:00, the ymd_hms() method ignores the time value, and the result becomes a date. Is there any way to show the 00:00:00 in the result? Thanks a lot!

推荐答案

因此,在Google搜索并尝试以下错误后,我才对这个问题有自己的答案:

So I just got my own answer to this question after google searches and error trying:

mydates <- format(as.POSIXct("2011-01-01 00:00:00", tz = "UTC"), "%m-%d-%Y %H:%M:%S")
mydates
[1] "01-01-2011 00:00:00"
format(as.POSIXct("2011-01-01 00:00:00", tz = "UTC"), "%m-%d-%Y %H:%M:%S")
[1] "01-01-2011 00:00:00"

似乎可以将R Base as.POSIXct与format参数一起使用.

It seems that using the R Base as.POSIXct with format arguments works.

这篇关于R lubridate包日期时间创建忽略了午夜的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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