strptime

Parsing string dates in ruby such as “28-May-10”

ε祈祈猫儿з 提交于 2019-12-01 20:46:56
I tried parsing using Date.parse("28-May-10").to_s Returns 0010-5-28 (which is 2000 years off!) How can I get ruby to interpret the two digit year properly. There are plenty of string to date conversion tricks out there on google but most handle digit months as opposed to "May". I prefer Date.strptime for this task: require 'date' puts Date.strptime("28-May-10", "%d-%b-%y") #2010-05-28 来源: https://stackoverflow.com/questions/9727898/parsing-string-dates-in-ruby-such-as-28-may-10

ValueError time data 'Fri Mar 11 15:59:57 EST 2016' does not match format '%a %b %d %H:%M:%S %Z %Y'

丶灬走出姿态 提交于 2019-12-01 17:51:39
I am trying to simply create a datetime object from the following date: 'Fri Mar 11 15:59:57 EST 2016' using the format: '%a %b %d %H:%M:%S %Z %Y'. Here's the code. from datetime import datetime date = datetime.strptime('Fri Mar 11 15:59:57 EST 2016', '%a %b %d %H:%M:%S %Z %Y') However, this results in a ValueError as shown below. ValueError: time data 'Fri Mar 11 15:59:57 EST 2016' does not match format '%a %b %d %H:%M:%S %Z %Y' Maybe I am missing something obviously wrong with my format string, but I have checked it over and over. Any help would be greatly appreciated, thanks. Edit to

Placing the grid along date tickmarks

一曲冷凌霜 提交于 2019-12-01 17:13:49
问题 I have the following data: x=strptime(20010101:20010110) y=1:10 z=data.frame(x,y) So my data is this: x y 1 2001-01-01 1 2 2001-01-02 2 3 2001-01-03 3 4 2001-01-04 4 5 2001-01-05 5 6 2001-01-06 6 7 2001-01-07 7 8 2001-01-08 8 9 2001-01-09 9 10 2001-01-10 10 When I create a plot in base using: plot(x,y) grid(NULL,NULL) My vertical grid does not align with the date tick marks. I know this seems like a pretty simple problem, but I have not found a solution to this anywhere. Is there a way to get

time.strptime() - argument 0 must be str, not bytes

本秂侑毒 提交于 2019-12-01 09:22:25
问题 Obviously I'm aware already that strftime and strptime doesn't like byte strings as parameters, however i'm in a pickle here because I sort of need to read a file content which has different character encodings saved in it and i need to handle them all, and send the time portion of each line in this text-file to strptime() . A quick fix would be to split the string, making sure the time simply contains numbers and dashes, but is it possible to somehow pass the byte object without trying to

Extracting time from character string with strptime() in R, returning NA

ぃ、小莉子 提交于 2019-11-30 19:35:35
I am trying to extract out the time from a character string in R and can't stop getting NA as a result. I have tried numerous variations of the regular expression tags, but can't seem to get around this simple problem. Any help/clarifications are appreciated. Here is my code for an example: > x [1] "2/7/2013 7:43" > class(x) [1] "character" > z <- strptime(x, "%H:%M") > z [1] NA R doesn't know that your string is a datetime. So make it one first: y <- strptime(x, format='%m/%d/%Y %H:%M') If you were trying to get just the date, you could do: strptime(x, '%m/%d/%Y') Because strptime discards

python datetime strptime wildcard

故事扮演 提交于 2019-11-30 17:17:13
I want to parse dates like these into a datetime object: December 12th, 2008 January 1st, 2009 The following will work for the first date: datetime.strptime("December 12th, 2008", "%B %dth, %Y") but will fail for the second because of the suffix to the day number ('st'). So, is there an undocumented wildcard character in strptime? Or a better approach altogether? Try using the dateutil.parser module. import dateutil.parser date1 = dateutil.parser.parse("December 12th, 2008") date2 = dateutil.parser.parse("January 1st, 2009") Additional documentation can be found here: http://labix.org/python

How to parse timezone with colon

╄→гoц情女王★ 提交于 2019-11-30 16:26:18
问题 Is there a way to parse timezone in "+00:00" format with datetime.strptime ? For instance: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In tel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from datetime import datetime >>> datetime.strptime("12:34:56+0000", "%X%z") datetime.datetime(1900, 1, 1, 12, 34, 56, tzinfo=datetime.timezone.utc) >>> datetime.strptime("12:34:56+00:00", "%X%z") Traceback (most recent call last):

str to time in python

雨燕双飞 提交于 2019-11-30 11:32:04
问题 time1 = "2010-04-20 10:07:30" time2 = "2010-04-21 10:07:30" How to convert the above from string to time stamp? I need to subtract the above timestamps time2-time1 . 回答1: For Python 2.5+ from datetime import datetime format = '%Y-%m-%d %H:%M:%S' print datetime.strptime(time2, format) - datetime.strptime(time1, format) # 1 day, 0:00:00 Edit: for Python 2.4 import time format = '%Y-%m-%d %H:%M:%S' print time.mktime(time.strptime(time2, format)) - time.mktime(time.strptime(time1, format)) #

Convert unicode to datetime proper strptime format

送分小仙女□ 提交于 2019-11-30 06:36:57
I am trying to convert a unicode object to a datetime object. I read through the documentation: http://docs.python.org/2/library/time.html#time.strptime and tried datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%SZ') but I get the error message ValueError: time data '2014-01-15T01:35:30.314Z' does not match format '%Y-%m-%dT%H:%M:%SZ' Any feedback on what is the proper format? I appreciate the time and expertise. You can parse the microseconds: from datetime import datetime date_posted = '2014-01-15T01:35:30.314Z' datetime.strptime(date_posted, '%Y-%m-%dT%H:%M:%S.%fZ') One option is to let

python datetime strptime wildcard

北战南征 提交于 2019-11-30 00:48:19
问题 I want to parse dates like these into a datetime object: December 12th, 2008 January 1st, 2009 The following will work for the first date: datetime.strptime("December 12th, 2008", "%B %dth, %Y") but will fail for the second because of the suffix to the day number ('st'). So, is there an undocumented wildcard character in strptime? Or a better approach altogether? 回答1: Try using the dateutil.parser module. import dateutil.parser date1 = dateutil.parser.parse("December 12th, 2008") date2 =