将Oracle时间戳记转换为R中的日期/时间 [英] Convert Oracle Timestamp to Date/Time in R

查看:267
本文介绍了将Oracle时间戳记转换为R中的日期/时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常从 Oracle 中读取数据到 R 。为了解决我的一些表格中的 TIMESTAMP 格式,我在列中以 TO_CHAR 在我的SQL语句中。

I often read data from Oracle into R. To get around the TIMESTAMP format in some of my tables, I read in the column in as a character string with TO_CHAR in my SQL statement.

但是,我想将字符串中保存的数据转换为R可以利用的日期+时间格式。不幸的是,我不知道如何最好地做到这一点,特别是考虑AM / PM组件。剥离日期很简单,但我不知道如何保留每个记录的时间部分。

However, I want to convert the data held in the string back into a date + time format that R can utilize. Unfortunately,I have no idea as to how to best do this, especially considering the AM/PM component. Stripping out the date is easy enough, but I have no idea as to how to retain the time part of each record.

以下是一些数据记录:

c("31-JUL-12 10.08.35.432 AM", "31-JUL-12 08.53.18.316 AM", "18-JUL-12 01.17.52.939 PM", 
"13-AUG-12 05.34.11.405 PM", "15-AUG-12 02.04.31.505 PM", "21-AUG-12 09.10.03.976 AM"
)

一个注意事项:这些数据是时区EST。

One note: these data are timezone EST.

任何帮助将不胜感激!

推荐答案

如果您处理日期/时间多,您应该熟悉?strptime

If you deal with dates/times much, you should familiarize yourself with ?strptime

> strptime(oracle, format='%d-%b-%y %I.%M.%OS %p', tz='America/New_York')
[1] "2012-07-31 10:08:35.432 EDT" "2012-07-31 08:53:18.316 EDT" "2012-07-18 13:17:52.939 EDT" "2012-08-13 17:34:11.405 EDT" "2012-08-15 14:04:31.505 EDT" "2012-08-21 09:10:03.976 EDT"

我认为EST你真的是在纽约纽约的东部时间。从帮助(时区)

Note that I assumed that by "EST" you really meant Eastern time in New York, NY. From help(timezone):


请注意,这些名称中的一些可能不是您的想法:特别是EST是加拿大使用的无夏令时间的时区,而不是EST5EDT或(澳大利亚)东部标准时间。

Beware that some of these designations may not be what you think: in particular EST is a time zone used in Canada without daylight savings time, and not EST5EDT nor (Australian) Eastern Standard Time.

这篇关于将Oracle时间戳记转换为R中的日期/时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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