strptime

Python ImportError for strptime in spyder for windows 7

为君一笑 提交于 2019-12-22 04:42:31
问题 I can't for the life of me figure out what is causing this very odd error. I am running a script in python 2.7 in the spyder IDE for windows 7. It uses datetime.datetime.strptime at one point. I can run the code once and it seems fine (although I haven't finished debugging, so exceptions have been raised and it hasn't completed normally yet), then if I try running it again I get the following (end of traceback only is shown): File "C:\path\to\test.py", line 220, in std_imp self.data[key]

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-19 19:56:00
问题 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

Milliseconds puzzle when calling strptime in R

笑着哭i 提交于 2019-12-17 16:58:35
问题 options(digits.secs = 3); > strptime("2007-03-30 15:00:00.007", format = "%Y-%m-%d %H:%M:%OS"); [1] "2007-03-30 15:00:00.007" > strptime("2007-03-30 15:00:00.008", format = "%Y-%m-%d %H:%M:%OS"); [1] "2007-03-30 15:00:00.008" > strptime("2007-03-30 15:00:00.009", format = "%Y-%m-%d %H:%M:%OS"); [1] "2007-03-30 15:00:00.008" > strptime("2007-03-30 15:00:00.010", format = "%Y-%m-%d %H:%M:%OS"); [1] "2007-03-30 15:00:00.01" > strptime("2007-03-30 15:00:00.011", format = "%Y-%m-%d %H:%M:%OS"); [1

unknown timezone name in R strptime/as.POSIXct

雨燕双飞 提交于 2019-12-17 16:30:18
问题 Where can I find a list of all legal time names for R function as.POSIXct ? as.POSIXct("1970-01-01",tz="CST") generates a warning that "CST" (Central Standard Time) is unknown. 回答1: ?Sys.timezone has some hints, specifically to look in: "R_HOME/share/zoneinfo/zone.tab" ( R_HOME is the directory R is installed in). Keep in mind that time zones are nasty and many of their nuances are operating system (and locale?) specific. In your specific case, you want "CST6CDT" instead of "CST" . 回答2:

Changing date format in R

不羁岁月 提交于 2019-12-17 06:35:55
问题 I have some very simple data in R that needs to have its date format changed: date midpoint 1 31/08/2011 0.8378 2 31/07/2011 0.8457 3 30/06/2011 0.8147 4 31/05/2011 0.7970 5 30/04/2011 0.7877 6 31/03/2011 0.7411 7 28/02/2011 0.7624 8 31/01/2011 0.7665 9 31/12/2010 0.7500 10 30/11/2010 0.7734 11 31/10/2010 0.7511 12 30/09/2010 0.7263 13 31/08/2010 0.7158 14 31/07/2010 0.7110 15 30/06/2010 0.6921 16 31/05/2010 0.7005 17 30/04/2010 0.7113 18 31/03/2010 0.7027 19 28/02/2010 0.6973 20 31/01/2010 0

How to convert string with UTC offset

一世执手 提交于 2019-12-13 07:44:06
问题 I have date as In [1]: a = "Sun 10 May 2015 13:34:36 -0700" When I try to convert it using strptime, its giving error. In [3]: datetime.strptime(a, "%a %d %b %Y %H:%M:%S %Z" ...: ) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-3-973ef1c6daca> in <module>() ----> 1 datetime.strptime(a, "%a %d %b %Y %H:%M:%S %Z" 2 ) /usr/lib/python2.7/_strptime.pyc in _strptime(data_string, format) 323 if not found: 324

Retrieving a date from a complex string in Python

*爱你&永不变心* 提交于 2019-12-12 13:47:18
问题 I'm trying to get a single datetime out of two strings using datetime.strptime. The time is pretty easy (ex. 8:53PM), so I can do something like: theTime = datetime.strptime(givenTime, "%I:%M%p") However, the string has more than just a date, it's a link in a format similar to http://site.com/?year=2011&month=10&day=5&hour=11 . I know that I could do something like: theDate = datetime.strptime(givenURL, "http://site.com/?year=%Y&month=%m&day=%d&hour=%H") but I don't want to get that hour from

Why %z is not supported by python's strptime?

与世无争的帅哥 提交于 2019-12-12 13:18:41
问题 >>> datetime.strptime('2014-02-13 11:55:00 -0800', '%Y-%m-%d %H:%M:%S %z') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/_strptime.py", line 317, in _strptime (bad_directive, format)) ValueError: 'z' is a bad directive in format '%Y-%m-%d %H:%M:%S %z' I understand that it's not supported, but don't know why. Seems it's not hard to support that. And 'Offset from UTC' is not as ambiguous as

ArgumentError: invalid strptime format - `%m/%d/%y' work around

风格不统一 提交于 2019-12-12 05:28:02
问题 I am in the process of working with an sftp import bug in which I'm trying to flag any dates that are imported that are incorrect. There are two types of dates that could be off. The first is when the year is in the future, or way in the past; the second is when the actual months and days are too high. (Example, 13/20/1995, or 11/35/2000) I'm using strptime and for dates that are off, flagging them and displaying them as a specific message. The problem I'm running into is that with the

create a list of datetime objects using datetime.strptime

你。 提交于 2019-12-11 23:15:52
问题 I have a list of strings. date_str = ["2012-11-04 1:05:21", "2013-11-03 1:05:21", "2014-11-02 1:07:31"] I want to read them as datetime objects. For one string, I do datetime.strptime(date_str[1], "%Y-%m-%d %H:%M:%S") but I don't know how to create a list of datetime objects. If I use datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S") I get this error: TypeError: must be string, not list I tried using a loop: x = datetime.strptime(date_str[0], "%Y-%m-%d %H:%M:%S") for i in range(1,len(date_str)