python - How to convert "01 January 2016" to UTC ISO format? -


so have following string : " 01 january 2016" utc iso date format ?

i'm using arrow module , following code, it's full of errors, , thinking may be, there smaller more elegent solution python encourages elegant , easier ways things, anyways here's code :

updatestr = " 01 january 2016" #note space @ beginning datelist = updatestr.split[' '] datedict = {"day" : datelist[1],"month": months.index(datelist[2])+1, "year" : datelist[3]} datestr = str(datedict['day']) + "-" + str(datedict["month"]) + "-" + str(datedict["year"]) dateiso = arrow.get(datestr, 'yyyy-mm-dd hh:mm:ss') 

please me have convert utc iso formats, months list of months in year .

you can use datetime:

>>> updatestr = " 01 january 2016" >>> import datetime dt >>> dt.datetime.strptime(updatestr, " %d %b %y") datetime.datetime(2016, 1, 1, 0, 0) >>> _.isoformat() '2016-01-01t00:00:00' 

keep in mind 'naive' object without timezone. check out pytz deal timezones elegantly, or add appropriate utcoffset datetime object utc.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -