Python: Date and Time

Image result for python background


Import the datetime module and display the current date:
import datetime

x = datetime.datetime.now()
print(x)


 The datetime() class also takes parameters for time and timezone (hour, minute, second, microsecond, tzone), but they are optional, and has a default value of 0, (None for timezone).

To create a date, we can use the datetime() class (constructor) of the datetime module.

The method is called strftime(), and takes one parameter, format, to specify the format of the returned string:

.

Newest