Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将时间戳/区域转换为R日期时间_R_Timestamp With Timezone - Fatal编程技术网

将时间戳/区域转换为R日期时间

将时间戳/区域转换为R日期时间,r,timestamp-with-timezone,R,Timestamp With Timezone,我有以下时间戳: “03-APR-06 12.41.00.000000000美国/中部下午” 需要将其转换为与R兼容的时间戳 我试过: structure(df2$ACTION_IN_DTTM_TZ,class=c('POSIXct')) parse_date_time(df2$ACTION_IN_DTTM_TZ, "abdHMSzY") strptime(df2$ACTION_IN_DTTM_TZ,format='%d/%b/%Y:%H:%M:%S:%p:%Z') 它们都生成了NAs str

我有以下时间戳:
“03-APR-06 12.41.00.000000000美国/中部下午”
需要将其转换为与R兼容的时间戳

我试过:

structure(df2$ACTION_IN_DTTM_TZ,class=c('POSIXct'))
parse_date_time(df2$ACTION_IN_DTTM_TZ, "abdHMSzY")
strptime(df2$ACTION_IN_DTTM_TZ,format='%d/%b/%Y:%H:%M:%S:%p:%Z')
它们都生成了NAs

structure(df2$ACTION_IN_DTTM_TZ,class=c('POSIXct'))
parse_date_time(df2$ACTION_IN_DTTM_TZ, "abdHMSzY")
strptime(df2$ACTION_IN_DTTM_TZ,format='%d/%b/%Y:%H:%M:%S:%p:%Z')
我想这样:
2012-08-1004:42:47


非常感谢您的任何建议!谢谢大家!

Package
lubridate
为此提供了功能。我用一个简单的str_extract命令提取了时区

library(lubridate)
library(stringr)
timestamp <- "03-APR-06 12.41.00.000000000 PM US/CENTRAL"
as_datetime(timestamp,tz=str_extract(timestamp,"\\S*$"))
[1] "2003-04-06 00:41:00 CST"

#without lubridate
strptime(strsplit(timestamp," \\S*$")[[1]][1],format="%y-%b-%d %I.%M.%S.%OS %p",tz=str_extract(timestamp,"\\S*$"))
库(lubridate)
图书馆(stringr)
时间戳我做了如下操作:

a <-  "03-APR-06 12.41.00.000000000 PM US/CENTRAL"
b <- (substr(a,1,18))
c <- as.POSIXct(b,format='%d-%b-%y %H.%M.%S')

a当我使用它时,我得到以下错误:C_force_tz(time,tz=tzone,roll)中的错误:CCTZ:unrecogned output timezone:“US/CENTRAL”非常有趣,对我来说运行没有问题。我正在使用
stringr\u 1.3.1
lubridate\u 1.7.4
//编辑:我刚刚重新启动了我的R会话,只加载了这两个包。它仍然可以正常工作,所以也许可以尝试重新启动您的会话?我正在一个大集群上运行它。谢谢!我知道不久前lubridate中有一个bug,有时会抛出这样的错误。所以也许你的集群上安装了一个旧版本,我编辑了一个基本的问题解决方案,希望这对你有用。嗨,Pietro,,谢谢!!