diff options
| author | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
|---|---|---|
| committer | 冯昶 <seaker@qq.com> | 2021-03-15 18:13:51 +0800 |
| commit | 8b6be37fe4dac8b4c6489a95e55514b76b298d15 (patch) | |
| tree | ae36c8ec2c71f606c0e36adaa19dba366a68a0b4 /challenge-100/paulo-custodio/python/ch-1.py | |
| parent | 865acfd056fb6f409ec6b1a81d60b931cbcb69fe (diff) | |
| parent | c9aec2da6bcb04b488183f09ca94bee488557aff (diff) | |
| download | perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.gz perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.tar.bz2 perlweeklychallenge-club-8b6be37fe4dac8b4c6489a95e55514b76b298d15.zip | |
Merge branch 'master' of github.com:seaker/perlweeklychallenge-club
Diffstat (limited to 'challenge-100/paulo-custodio/python/ch-1.py')
| -rw-r--r-- | challenge-100/paulo-custodio/python/ch-1.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/challenge-100/paulo-custodio/python/ch-1.py b/challenge-100/paulo-custodio/python/ch-1.py new file mode 100644 index 0000000000..7cabc2f1a7 --- /dev/null +++ b/challenge-100/paulo-custodio/python/ch-1.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +# Challenge 100 +# +# TASK #1 > Fun Time +# Submitted by: Mohammad S Anwar +# You are given a time (12 hour / 24 hour). +# +# Write a script to convert the given time from 12 hour format to 24 hour format +# and vice versa. +# +# Ideally we expect a one-liner. +# +# Example 1: +# Input: 05:15 pm or 05:15pm +# Output: 17:15 +# Example 2: +# Input: 19:15 +# Output: 07:15 pm or 07:15pm + +import re; +import sys; +import datetime; + +if re.search(r'am|pm', sys.argv[1], re.I): + t = datetime.datetime.strptime(sys.argv[1], "%I:%M%p") + print(t.strftime("%H:%M")) +else: + t = datetime.datetime.strptime(sys.argv[1], "%H:%M") + print(t.strftime("%I:%M%p").lower()) |
