You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Python/Convert_US_Date_to_EU_Date.py
+13-4Lines changed: 13 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -31,17 +31,26 @@
31
31
# Import the regex package
32
32
importre
33
33
34
-
# Import the time package
34
+
# Import the datetime package
35
35
fromdatetimeimportdatetime
36
36
37
+
# Use regex to identify if the first character of the input is a capital letter (first letter of a month)
37
38
USDateStrRe=re.match(r'[A-Z]',USDateStr)
39
+
40
+
# Use dateime.strptime to create a date object based on the result of the regex match.
38
41
if (USDateStrReisNone):
39
-
#date is 11/19/2019 format
42
+
# If there was no result from the Regex search, date is 11/19/2019 format
40
43
USDate=datetime.strptime(USDateStr,'%m/%d/%Y')
41
44
else:
42
-
#date is in November 19, 2019 format
45
+
# If there there was a result from the Regex search, date is in November 19, 2019 format
46
+
# %B is the full month name
43
47
USDate=datetime.strptime(USDateStr,'%B %d, %Y')
44
48
45
-
EUDate=datetime.strftime(USDate,'%d/%m/%Y')
49
+
# Use dateime.strftime to convert the date object into a string of the required formate.
50
+
# To remove the leading zeros from the date (as required by the puzzle) on Linux/Android, use a hyphen between the % and the letter code. (This is the solution that will run on Sololearn)
51
+
EUDate=datetime.strftime(USDate,'%-d/%-m/%Y')
52
+
53
+
# To remove the leading zeros from the date (as required by the puzzle) on Windows, use a pound sign between the % and the letter code.
0 commit comments