Problem domain:
Format 1:
from datetime import datetime
now = datetime.now()
print now
print now.year
print now.month
print now.day
Format 2:
from datetime import datetime
now = datetime.now()
print '%s/%s/%s' % (now.month, now.day, now.year, )
Format 3: from datetime import datetime
now = datetime.now()
print '%s:%s:%s' % (now.hour, now.minute, now.second )
Format 4: from 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 )
- Create a variable called
now
and store the result ofdatetime.now()
in it. - Then,
print
the value ofnow
.
Solve:
from datetime import datetime
now = datetime.now()
print now
Output:
current date
Printing current date year and month code
Format 1:
now = datetime.now()
print now
print now.year
print now.month
print now.day
now = datetime.now()
print '%s/%s/%s' % (now.month, now.day, now.year, )
Format 3: from datetime import datetime
now = datetime.now()
print '%s:%s:%s' % (now.hour, now.minute, now.second )
Format 4: from 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 )
No comments:
Post a Comment