python-dateutil

Get tz offset from string

亡梦爱人 提交于 2019-12-24 17:04:28
问题 I have a date which is in local time: date: "2013-12-02 22:00:00" and another value the tz: timezone_offset: "GMT-0800" If I : dateutil.parser.parse(date).isoformat() I will get: "2013-12-02T22:00:00+0000" I want to implement the date in ISO format with the tz info and get a result of: "2013-12-02T22:00:00-0800" Something close to: parse(date,tzinfos=??).isoformat() ? How can I get the tzinfo from the string timezone_offset ? 回答1: >>> from dateutil.parser import parse >>> dt = parse("2013-12

python datetime.astimezone behavior incorrect?

爷,独闯天下 提交于 2019-12-23 16:32:08
问题 Here is the code which first parses time from string in IST and then converts that to UTC. So when it 4:00 pm in India the time in GMT / UTC is 10:30 am. While the following code prints it as 9:30 pm. So instead of subtracting the offset it is adding the offset. From the python documentation https://docs.python.org/2/library/datetime.html#datetime.datetime.astimezone the sample implementation of astimezone, it does appear that it would add the offset if it is negative but it seems contrary to

Installing python dateutil

我们两清 提交于 2019-12-20 10:15:42
问题 I tried to install python dateutil for my django tastypie but unsuccessful, http://labix.org/python-dateutil#head-2f49784d6b27bae60cde1cff6a535663cf87497b I downloaded the tar file in c:/python27 and unzipped it, I get the following error msg, **C:\Python27\Scripts>**easy_install dateutil-1.5 Searching for dateutil-1.5 Reading http://pypi.python.org/simple/dateutil-1.5/ Couldn't find index page for 'dateutil-1.5' (maybe misspelled?) Scanning index of all packages (this may take a while)

How to parse multiple dates from a block of text in Python (or another language)

戏子无情 提交于 2019-12-18 14:18:08
问题 I have a string that has several date values in it, and I want to parse them all out. The string is natural language, so the best thing I've found so far is dateutil. Unfortunately, if a string has multiple date values in it, dateutil throws an error: >>> s = "I like peas on 2011-04-23, and I also like them on easter and my birthday, the 29th of July, 1928" >>> parse(s, fuzzy=True) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/lib/pymodules/python2.7

ImportError: matplotlib requires dateutil

回眸只為那壹抹淺笑 提交于 2019-12-17 15:22:44
问题 I have successfully installed matplotlib with python 2.6 on x64 Windows7. When I try to import matplotlib, it shows the following error. I have also installed numpy following this link: Installing Numpy on 64bit Windows 7 with Python 2.7.3 import matplotlib.pyplot as plt Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> import matplotlib.pyplot as plt File "C:\Python26\Lib\site-packages\matplotlib\__init__.py", line 110, in <module> raise ImportError("matplotlib

Localize datetime (timezone aware) from timezone offset

痞子三分冷 提交于 2019-12-14 03:13:39
问题 I have a UTC timestamp and a timezone offset timestamp (both in milliseconds): utc_time = 1394452800000 timezoneoffset = -14400000 If I wanted to get the datetime I would do : print datetime.utcfromtimestamp(utc_time/1000) >>>2014-03-10 12:00:00 How can I localize this datetime but also the final object be timezone aware? If I divide timezoneoffset , -14400000/(3600*1000) = -4 (hours). So the final output should be: >>>2014-03-10 08:00:00-04:00 My try: from pytz import timezone from dateutil

Calculating average for relativedelta in python

只愿长相守 提交于 2019-12-13 04:00:53
问题 I have multiple relativedelta values in Python 3 and I would like to take an average of all these. For example, for the 2 values below, I would like a relativedelta value where hours = +3 day (average between the two). relativedelta(days=+2, hours=+1, minutes=+33, seconds=+51) relativedelta(hours=+4, minutes=+35, seconds=+36) How can I calculate the average between a list? If there was a way to get the total number of hours for each value, I could add them up and divide by number of values,

Python dateutil parser fails

限于喜欢 提交于 2019-12-12 14:40:15
问题 I am attempting to parse the following date strings obtained from email headers: from dateutil import parser d1 = parser.parse('Tue, 28 Jun 2011 01:46:52 +0200') d2 = parser.parse('Mon, 11 Jul 2011 10:01:56 +0200 (CEST)') d3 = parser.parse('Wed, 13 Jul 2011 02:00:01 +0000 (GMT+00:00)') The third one fails; am I missing something obvious? 回答1: have you tried parser.parse('...', fuzzy=True) ? (I suppose it works :)) 回答2: Give a try to parsedatetime library. In [16]: import parsedatetime

Can't upgrade python-dateutil in OSX

浪子不回头ぞ 提交于 2019-12-12 13:23:15
问题 I am trying to install Sphinx on OSX, with the hopes of eventually making it into a website, following this guide : I have been macporting, homebrewing, python wheelin', figuring out what a virtualenv is... figuring out if I should use python 2.7 or 3.X (which I couldn't figure out) I added this to my bash profile : export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages When I run this : python -c "import sys; print('\n'.join(sys.path))" I had expected it to return simply /usr

Cannot import name StringIO when importing dateutil

老子叫甜甜 提交于 2019-12-12 04:36:48
问题 I'm having a 'Cannot import name StringIO' error message when importing dateutil which tries to import StringIO but cannot find it. Here is complete trace: (DEV)arbi@el-oued:~/Work/sentimentpy$ python core/main.py Traceback (most recent call last): File "core/main.py", line 7, in <module> from io.reader import * File "/home/arbi/Work/sentimentpy/core/io/reader.py", line 4, in <module> from dateutil import parser File "/home/arbi/DEV/local/lib/python2.7/site-packages/dateutil/parser.py", line