Date and Time in Python

In this section of Python codecademy, one can learn how to import current date and exact time.

i.The datetime Library 1/6

from datetime import datetime

>Save and Submit

ii. Getting the Current Date and Time 2/6

from datetime import datetime
now = datetime.now()
print now

iii. Extracting Information 3/6

from datetime import datetime
now = datetime.now()
current_year = now.year
current_month = now.month
current_day = now.day
print current_year
print current_month
print current_day

iv. Hote Date 4/6

from datetime import datetime
now = datetime.now()

print ‘%s/%s/%s’ % (now.month, now.day, now.year)

v. Pretty Time 5/6

from datetime import datetime
now = datetime.now()

print ‘%s:%s:%s’ % (now.hour, now.minute, now.second)

vi. Grand Finale 6/6

rom datetime import datetime
now = datetime.now()
print ‘%s/%s/%s %s:%s:%s’ % (now.month, now.day, now.year, now.hour, now.minute, now.second)

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s