Python Datetime Example
Python Datetime Example using date and datetime Python libraries.
----------------------------------------------------
#Output
Today's date is: 2019-04-20
Date components: 4 20 2019
Today's weekday number is: 5
Which is a: Saturday
The current date and time is: 2019-04-20 06:59:32.920821
Current time: 06:59:32.920821
# # Python Datetime Example # from datetime import date from datetime import datetime def main(): ## DATE OBJECTS today = date.today() print("Today's date is: ", today) print("Date components: ", today.month, today.day, today.year) print("Today's weekday number is: ", today.weekday()) days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] print("Which is a: " + days[today.weekday()]) ## DATETIME OBJECTS today1 = datetime.now() print("The current date and time is: ", today1) time = datetime.time(datetime.now()) print("Current time: ", time) if __name__ == "__main__": main();
----------------------------------------------------
#Output
Today's date is: 2019-04-20
Date components: 4 20 2019
Today's weekday number is: 5
Which is a: Saturday
The current date and time is: 2019-04-20 06:59:32.920821
Current time: 06:59:32.920821
Comments
Post a Comment