Date in Python? | Sololearn: Learn to code for FREE!

0

Date in Python?

How do I get date from python like 1pm when it is 1pm?

11/3/2018 1:22:52 AM

Isak Nilsson

4 Answers

New Answer

+7

from datetime import datetime # both time & date print(datetime.now()) # only date print(datetime.now().date()) # only time print(datetime.now().time()) # hh:mm:ss AM/PM format print(datetime.now().strftime("%I:%M:%S %p")) Check out the docs for more: https://docs.python.org/3/library/datetime.html

+6

Kishalaya has answered well, just notice that on SoloLearn, the time will be of SoloLearn's server but not your device, because codes are executed there and then return the result to ours

+1

You're welcome, Skrub !

0