簡體   English   中英

在 R 中使用日期時間格式的設施:%Y-%m-%d %H:%M:%OS-0200

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

我有一個格式為27.04.2020 15:50:30.391-0700的日期時間字符串。 破折號后的0700表示相對於 GMT 的時區。

我發現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. R,到目前為止,我還想不出辦法; 我已經嘗試了很多字符串替換,as.character 等等(無濟於事)。

誰能證明我錯了?

您需要更改顯示選項以查看毫秒數。 試試這個:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM