Python strftime Example
Below code demonstrated the use of strftime method to format time using Python.
----------------------------------------------------
#Output
Sat, 20 April, 2019
Local date and time: Sat Apr 20 11:46:31 2019
Local date: 04/20/19
Local time: 11:46:31
Current time: 11:46:31 AM
24-hour time: 11:46
# # Python strftime Example # from datetime import datetime def main(): # Times and dates can be formatted using a set of predefined string now = datetime.now() print(now.strftime("%a, %d %B, %Y")) print(now.strftime("Local date and time: %c"))#Local date and time print(now.strftime("Local date: %x"))#Local date print(now.strftime("Local time: %X"))#Local time print(now.strftime("Current time: %I:%M:%S %p")) print(now.strftime("24-hour time: %H:%M")) if __name__ == "__main__": main();
----------------------------------------------------
#Output
Sat, 20 April, 2019
Local date and time: Sat Apr 20 11:46:31 2019
Local date: 04/20/19
Local time: 11:46:31
Current time: 11:46:31 AM
24-hour time: 11:46
Comments
Post a Comment