strptime

Parse timestamp with a.m./p.m

牧云@^-^@ 提交于 2019-12-04 03:44:25
I have a file that formats time stamps like 25/03/2011 9:15:00 p.m. How can I parse this text to a Date-Time class with either strptime or as.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") It appears the AM/PM indicator can't include punctuation.

2 digit years using strptime() is not able to parse birthdays very well

房东的猫 提交于 2019-12-04 03:17:05
问题 Consider the following birthdays (as dob ): 1-Jun-68 1-Jun-69 When parsed with Python’s datetime.strptime(dob, '%d-%b-%y') will yield: datetime.datetime(2068, 6, 1, 0, 0) datetime.datetime(1969, 6, 1, 0, 0) Well of course they’re supposed to be born in the same decade but now it’s not even in the same century! According to the docs this is perfectly valid behaviour: When 2-digit years are accepted, they are converted according to the POSIX or X/Open standard: values 69-99 are mapped to 1969

dplyr does not group data by date

别来无恙 提交于 2019-12-03 06:04:41
问题 I am trying to calculate the frequency of bikes that are taken by people using a dataset provided by Leada. Here is the code: library(dplyr) setAs("character", "POSIXlt", function(from) strptime(from, format = "%m/%d/%y %H:%M")) d <- read.csv("http://mandrillapp.com/track/click/30315607/s3-us-west-1.amazonaws.com?p

dplyr does not group data by date

泄露秘密 提交于 2019-12-02 19:31:30
I am trying to calculate the frequency of bikes that are taken by people using a dataset provided by Leada. Here is the code: library(dplyr) setAs("character", "POSIXlt", function(from) strptime(from, format = "%m/%d/%y %H:%M")) d <- read.csv("http://mandrillapp.com/track/click/30315607/s3-us-west-1.amazonaws.com?p

R strptime Monday date from weeknumber weird

对着背影说爱祢 提交于 2019-12-02 18:17:16
问题 I am making a trivial error here but cannot get my head around figuring out what is the problem. I need to get the date of the Monday of the week of a random date.. Seems I am getting something quite different mydate <- date("2013-11-05") format(mydate, "%A") # this is Tuesday, right #[1] "Tuesday" month(mydate) # Month November, right #[1] 11 myyr <- year(mydate); myyr # year is 2013, right #[1] 2013 day(mydate) # day number is 5, right #[1] 5 mywk <- isoweek(mydate);mywk # weeknumber is 45,

error in getting the correct date using strptime in R

安稳与你 提交于 2019-12-02 12:38:52
I'm using strptime to extract date and the result is a wrong year Where is the error in the below code: strptime('8/29/2013 14:13', "%m/%d/%y") [1] "2020-08-29 PDT" What are the other ways to extract date and time as separate columns. The data I have is in this format - 8/29/2013 14:13 I want to split this into two columns, one is 8/29/2013 and the other is 14:13 . You have a four digit year so you need to use %Y strptime('8/29/2013 14:13', "%m/%d/%Y" ) [1] "2013-08-29 CEST" Do you really want data and time in separate columns? It usually much easier to deal with a single date-time object.

Python - Time data not match format

岁酱吖の 提交于 2019-12-02 09:03:08
问题 I have string time in the following format 2016-12-10T13:54:15.294 I am using the following method to format the time: time.strptime(ts, '%b %d %H:%M:%S %Y') Which throws an error: time data did not match format: data=2016-12-10T13:54:15.294 fmt=%a %b %d %H:%M:%S %Y Any ideas where I am going wrong? 回答1: You need to first parse the string as its formatted, then print it out the way you want. >>> import datetime >>> ts = "2016-12-10T13:54:15.294" >>> parsed = datetime.datetime.strptime(ts, '%Y

datetime.strptime strange behavior [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-02 04:30:08
This question already has an answer here: Whats wrong with my datetime.strptime format? 1 answer I'm getting the following error on aws virtual machine running python 3.6.8, while on my laptop it works fine with python 3.6.1 return datetime.strptime(date_str, self.date_format) File "/usr/lib64/python3.6/_strptime.py", line 565, in _strptime_datetime tt, fraction = _strptime(data_string, format) File "/usr/lib64/python3.6/_strptime.py", line 362, in _strptime (data_string, format)) ValueError: time data 'Fri, 23 Aug 2019 20:24:46 IDT' does not match format '%a, %d %b %Y %H:%M:%S %Z' What's

Parse hours without leading zeroes by strptime in Python

走远了吗. 提交于 2019-12-02 00:07:14
问题 Suppose you have time in this format: a = [..., 800.0, 830.0, 900.0, 930.0, 1000.0, 1030.0, ...] The problem is that leading zeroes for hours are missing. For example 00:30 is represented by 30 , 08:00 is represented by 800. and 00:00 is represented by 2400 . Is it possible to parse this data to time object using strptime method? I tried using following code hours = [time.strptime(str(int(i)), "%H%M") for i in a] but got ValueError: unconverted data remains: 0 P.S. I'm using Python 2.7. 回答1:

Strange strptime behavior in R

…衆ロ難τιáo~ 提交于 2019-12-02 00:03:47
I experience very strange behaviour of strptime parsing. This is my R session on windows machine > R.Version()$version.string [1] "R version 2.15.2 (2012-10-26)" > a <- ( strptime( "29-MAR-13 02.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) ) > str(a) POSIXlt[1:1], format: "2013-03-29 02:26:53" > # convert to double: doesn't work > as.double(a) [1] NA > b <- ( strptime( "29-MAR-13 04.26.53.000000000 AM" , "%d-%B-%y %I.%M.%OS %p" ) ) > #same as `a`, but another hour > str(b) POSIXlt[1:1], format: "2013-03-29 04:26:53" > #convert to double: works > as.double(b) [1] 1364520413 > #WTF ??? I have