python - Convert Spanish date in string format? -


how convert date in string format compare current time?

i tried this:

import time, datetime  if time.strptime(date.find(text=true), "%a, %d/%m/%y").now() > datetime.now(): 

but error:

valueerror: time data u'dom, 07/02/2016' not match format '%a, %d/%m/%y' 

need advice on how this.

you need setup proper locale before handling language/region specific data.

try again with

import locale locale.setlocale(locale.lc_time, '') time.strptime(date_string, "%a, %d/%m/%y") 

the '' tells library pickup current locale of system (if 1 set).

if need parse date in different locale, situation little bit more complex. see how strftime date object in different locale? gritty details.

it possible explicitly set specific locale, e.g.

locale.setlocale(locale.lc_time, 'es_es.utf-8') time.strptime('dom, 01/02/1903', '%a, %d/%m/%y') => time.struct_time(tm_year=1903, tm_mon=2, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=6, tm_yday=32, tm_isdst=-1) 

but remember, settings global. strptime() not accept parameter specify particular locale parse with, picks global locale.

if date user-supplied, have used dateparser package welcome alternative. so, since parse() function accepts explicit languages parameter.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -