You can format a date and time using the strftime()
method provided by the datetime
module in Python. Here is an example of how you can format the current date and time in the format you specified:
main.py160 chars8 lines
In this code, we first import the datetime
module. Then, we get the current date and time using the now()
method of the datetime
class.
Next, we use the strftime()
method to format the date and time. The %B
directive represents the full month name, %d
represents the date, %Y
represents the year, %I
represents the hour in 12-hour format, %M
represents the minute, %S
represents the second, %f
represents the microsecond, %p
represents the AM/PM designator, and %Z
represents the timezone.
Finally, we print the formatted date and time using the print()
function. The output will look something like this:
main.py81 chars2 lines
gistlibby LogSnag