{"id":11845,"date":"2022-02-06T16:44:18","date_gmt":"2022-02-06T21:44:18","guid":{"rendered":"http:\/\/local.brightwhiz\/?post_type=snippets&p=11845"},"modified":"2022-02-06T16:44:20","modified_gmt":"2022-02-06T21:44:20","slug":"get-current-date-and-time-in-python","status":"publish","type":"snippets","link":"http:\/\/local.brightwhiz\/snippets\/get-current-date-and-time-in-python\/","title":{"rendered":"How to get Current Date and Time in Python"},"content":{"rendered":"\n
Using DateTime to print date and time:<\/p>\n\n\n\n
from datetime import datetime\nnow = datetime.now()\nprint("date and time now: ", now)\n\n#formtat the output\nprint (now.strftime("%Y-%m-%d %H:%M:%S"))\n\nOutput: 2022-01-19 11:24:32<\/code><\/pre>\n\n\n\nUsing date:<\/p>\n\n\n\n
from datetime import date\n\ntoday = date.today()\nprint("Today's date:", today)<\/code><\/pre>\n","protected":false},"comment_status":"open","ping_status":"closed","template":"","meta":[],"categories":[953,15],"tags":[954,471,475],"yoast_head":"\nHow to get Current Date and Time in Python<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n