InterviewSolution
Saved Bookmarks
| 1. |
Formatting Dates in Python |
|
Answer» To handle date and time operations in Python, we use the datetime module.
Example: import datetimetm = datetime.time(1, 30, 11, 22) print(tm) Output: 01:30:11.000022
Example: import datetimedate = datetime.date(2000, 11, 16) print('Date date is ', date.day, ' day of ', date.month, ' month of the year ', date.year) Output: Date date is 16 day of 11 month of the year 2000
Example: from datetime import datetimeprint(datetime.strptime('15/11/2000', '%d/%m/%Y')) Output: 2000-11-15 00:00:00
For example: from time import gmtime, strftimes = strftime("%a, %d %b %Y %H:%M:%S + 1010", gmtime()) print(s) Output: Sun, 28 Nov 2021 18:51:24 + 1010 |
|