English 中文(简体)
页: 1
原标题:Parse timestamp with a.m./p.m

我有文件显示,格式时标象25/03/2011 9:1 5 p.m.

如何将这一案文同以下几类时间段相提并论:strptimecode。 POSIXct ?

Here is what almost works:

> as.POSIXct("25/03/2011 9:15:00", format="%d/%m/%Y %I:%M:%S", tz="UTC")
[1] "2011-03-25 09:15:00 UTC"

Here is what is not working, but I d like to have working:

> as.POSIXct("25/03/2011 9:15:00 p.m.", format="%d/%m/%Y %I:%M:%S %p", tz="UTC")
[1] NA

I m using R version 2.13.2 (2011-09-30) on MS Windows. My working locale is "C":

Sys.setlocale("LC_TIME", "C")
最佳回答

看来,AM/PM指标可能不包括校准。 在删除图解之后询问:

td <- "25/03/2011 9:15:00 p.m."
tdClean <- gsub("(.)\.?[Mm]\.?","\1m",td)
as.POSIXct(tdClean, format="%d/%m/%Y %I:%M:%S %p", tz="UTC")
# [1] "2011-03-25 21:15:00 UTC"
问题回答

就在这一点上,因为你可以使用<条码>指示/编码>一揽子方案。

library(stringr)
data$date2 <- str_sub(data$date, end = -4) 
# this removes the punctuation but holds onto the A/P values
data$date2 <- str_c(data$date2,  m ) 
# adds the required m




相关问题
Change the date format in kibana

I am working for my internship on the implementation of the ElasticSearch family (ElasticSearch+ Kibana+ logstash). Here is my question: I have a field "@ timestamp" with the following format: 2014-05-...

Quickly getting to YYYY-mm-dd HH:MM:SS in Perl

When writing Perl scripts I frequently find the need to obtain the current time represented as a string formatted as YYYY-mm-dd HH:MM:SS (say 2009-11-29 14:28:29). In doing this I find myself taking ...

Sorting by unknown column type in mysql

So I ve got a users table; storing things like username, email, etc. I then have a user_settings table. Instead of standard columns like timestamp_logged_in, profile_views, etc., I have it organized ...

timestamp date today

Hi guys could you please help me with this. I know it is silly but can t find unswer anywhere: I have a query that shows events from the today time_stamp but I want to include today as well. How do I ...

connection time zone issue with jOra eclipse plugin

I started using the jOra eclipse plugin. The plugin seems pretty robust and I m hoping to stop using SQLDeveloper for 95% of my database needs. Many of our tables have columns of type TIMESTAMP ...

How to get a UNIVERSAL Windows batch file timestamp

I m having trouble generating a timestamp in a Windows batch file, because I get diferent date formats on different Windows versions. My machine: >echo %date% >Tue 11/17/2009 Friends machine: ...

热门标签