+ 2
Date conversion US to EU.Can anyone make it more simple?
3 Antworten
+ 3
Try this:
month = {'January':'1','February':'2','March':'3','April':'4','May':'5','June':'6','July':'7','August':'8','September':'9','October':'10','November':'11','December':'12'}
date = input()
date = date.replace(', ', '/')
date = date.replace(' ', '/')
list = date.split('/')
if list[0] in month:
list[0] = month[list[0]]
date = list[1]+'/'+list[0]+'/'+list[2]
print(date)
+ 1
# ------ Date converter ------
import re
x = input()
sea = re.compile(r'(\d\d|\d)?/(\d|\d\d)?/(\d{4})')
mo1 = sea.findall(x)
if mo1 != []:
date_regex = re.compile(r'(\d\d|\d)?/(\d|\d\d)?/(\d{4})')
mo = date_regex.search(x)
print(f'{mo.group(2)}/{mo.group(1)}/{mo.group(3)}')
else:rt
name_d = re.compile(r'(\w*) (\d|\d\d),(\d{4})')
mo = name_d.search(x)
if mo.group(1) == 'January':
print(f'{mo.group(2)}/1/{mo.group(3)}')
elif mo.group(1) == 'February':
print(f'{mo.group(2)}/2/{mo.group(3)}')
elif mo.group(1) == 'March':
print(f'{mo.group(2)}/3/{mo.group(3)}')
elif mo.group(1) == 'April':
print(f'{mo.group(2)}/4/{mo.group(3)}')
elif mo.group(1) == 'May':
print(f'{mo.group(2)}/5/{mo.group(3)}')g
elif mo.group(1) == 'June':
print(f'{mo.group(2)}/6/{mo.group(3)}')
elif mo.group(1) == 'July':
print(f'{mo.group(2)}/7/{mo.group(3)}')
elif mo.group(1) == 'August':
print(f'{mo.group(2)}/8/{mo.group(3)}')
elif mo.group(1) == 'September':
print(f'{mo.group(2)}/9/{mo.group(3)}')
elif mo.group(1) == 'October':
print(f'{mo.group(2)}/10/{mo.group(3)}')
elif mo.group(1) == 'November':
print(f'{mo.group(2)}/11/{mo.group(3)}')
elif mo.group(1) == 'December':
print(f'{mo.group(2)}/12/{mo.group(3)}')
0
Thanks, I want to know better logic as i,m new to coding.Thanks for u suggetion