>>> from datetime import datetime
>>> d = datetime.strptime("10:30", "%H:%M")
>>> d.strftime("%I:%M %p")
'10:30 AM'
>>> d = datetime.strptime("22:30", "%H:%M")
>>> d.strftime("%I:%M %p")
'10:30 PM'
More Related Contents:
- How to use % symbol correctly
- How to match a string to pattern “Foo-Bar”, where Bar can be any element of a list? [closed]
- Searching for IP addresses in a file
- Swapping variable places inside if throws an error
- How to remove English words from a file containing Dari words?
- How can I read inputs as numbers?
- Behavior of exec function in Python 2 and Python 3
- Why is a list comprehension so much faster than appending to a list?
- How to print a string at a fixed width?
- How to use pip with Python 3.x alongside Python 2.x
- Why is parenthesis in print voluntary in Python 2.7?
- Format a datetime into a string with milliseconds
- How can I make a for-loop pyramid more concise in Python? [duplicate]
- Backporting Python 3 open(encoding=”utf-8″) to Python 2
- Getting only element from a single-element list in Python?
- Why does this not work as an array membership test? [duplicate]
- Accessing attributes on literals work on all types, but not `int`; why? [duplicate]
- Using multiple Python engines (32Bit/64bit and 2.7/3.5)
- Python regex for unicode capitalized words
- ImportError on python 3, worked fine on python 2.7
- How to get Windows short file name in python?
- What does the “yield” keyword do in Python?
- How to create a Python dictionary with double quotes as default quote format?
- Python 3 urllib produces TypeError: POST data should be bytes or an iterable of bytes. It cannot be of type str
- How can I use f-string with a variable, not with a string literal?
- Switch between python 2.7 and python 3.5 on Mac OS X
- Multiple keys per value
- WinError 2 The system cannot find the file specified (Python)
- Run process with realtime output to a Tkinter GUI
- What does the slice() function do in Python?