简体   繁体   English

在 R 中使用日期时间格式的设施:%Y-%m-%d %H:%M:%OS-0200

[英]Facilities to work with datetime format in R: %Y-%m-%d %H:%M:%OS-0200

I have a datetime string in a format of 27.04.2020 15:50:30.391-0700 .我有一个格式为27.04.2020 15:50:30.391-0700的日期时间字符串。 0700 after dash was to denote the timezone relative to GMT.破折号后的0700表示相对于 GMT 的时区。

I found it kind of annoying in R as there is no known tools to work with this type of non-standard datetime format.我发现R有点烦人,因为没有已知的工具可以处理这种类型的非标准日期时间格式。 I use R way more than python on a daily basis, yet pandas is just very intuitive to use for this and pandas can actually do time diff directly on these format when they are proper python datetime objects. I use R way more than python on a daily basis, yet pandas is just very intuitive to use for this and pandas can actually do time diff directly on these format when they are proper python datetime objects. R, as of this minute I could not figure out a way to do it; R,到目前为止,我还想不出办法; I've experimented quite a bit of string replacing, as.character and more (to no avail).我已经尝试了很多字符串替换,as.character 等等(无济于事)。

Can anyone prove me wrong?谁能证明我错了?

You need to change display options to see the milliseconds.您需要更改显示选项以查看毫秒数。 Try this one:试试这个:

library(lubridate)

time_string <- '27.04.2020 15:50:30.391-0700'
time_lubridate <- dmy_hms(time_string)
options(digits.secs=3)
time_lubridate

> time_lubridate
[1] "2020-04-27 22:50:30.391 UTC"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Pandas:将日期时间 (%Y-%d-%m %H:%M) 转换为 (%Y-%m-%d %H:%M) - Pandas: Converting a datetime (%Y-%d-%m %H:%M) to (%Y-%m-%d %H:%M) 如何将日期时间从十进制转换为“%y-%m-%d%H:%M:%S”给定时间原点? - How to convert datetime from decimal to “%y-%m-%d %H:%M:%S” given the time origin? Python:与格式“%Y-%m-%d %H:%M:%S”不匹配 - Python: does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据“无”与格式“%Y-%m-%d %H:%M:%S”不匹配 - ValueError: time data 'None' does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据 '' 与格式 '%Y-%m-%d %H:%M' 不匹配 - ValueError: time data '' does not match format '%Y-%m-%d %H:%M' 时间数据与格式 '%Y-%m-%d %H:%M:%S' 不匹配 - time data does not match format '%Y-%m-%d %H:%M:%S' ValueError:时间数据“ 140120 1520”与格式“%Y-%m-%d%H:%M:%S”不匹配 - ValueError: time data '140120 1520' does not match format '%Y-%m-%d %H:%M:%S' ValueError: 时间数据与格式 &#39;%Y-%m-%d %H:%M:%S.%f&#39; 不匹配 - ValueError: time data does not match format '%Y-%m-%d %H:%M:%S.%f' 出现错误“ValueError:时间数据&#39;&#39;与格式&#39;%Y-%m-%d %H:%M:%S&#39;不匹配” - Getting error "ValueError: time data '' does not match format '%Y-%m-%d %H:%M:%S'" 将 Twitter 新日期格式转换为日期时间 ( %Y-%m-%d %H:%M%S' ) - Convert Twitter New Date Format to Date Time ( %Y-%m-%d %H:%M%S' )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM