Created
December 15, 2013 22:12
-
-
Save tkmru/7978918 to your computer and use it in GitHub Desktop.
This is easy way to get date and datetime.
It use str().
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> from datetime import datetime | |
| >>> now = datetime.now() | |
| >>> now.strftime('%Y-%m-%d %H:%M:%S') #hard | |
| '2013-10-06 07:59:20' | |
| >>> str(now) | |
| '2013-10-06 07:59:20.532184' | |
| >>> str(now).split('.')[0] #easy | |
| '2013-10-06 07:59:20 | |
| >>> from datetime import date | |
| >>> today = date.today() | |
| >>> today.strftime('%Y-%m-%d') #hard | |
| '2013-10-06' | |
| >>> str(today) #easy | |
| '2013-10-06' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment