now_time.py
from datetime import datetime
datetime.now().strftime("%Y/%m/%d %H:%M:%S")
from datetime import datetime
commander | résultat |
---|---|
datetime.now() | datetime.datetime(2014, 1, 2, 3, 4, 5, 000000) |
from datetime import datetime, timedelta
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5) | datetime.datetime(2014, 1, 2, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(weeks=1) | datetime.datetime(2014, 1, 9, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(days=1) | datetime.datetime(2014, 1, 3, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(hours=1) | datetime.datetime(2014, 1, 2, 4, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(minutes=1) | datetime.datetime(2014, 1, 2, 3, 5, 5) |
datetime(2014,1,2,3,4,5) + timedelta(seconds=1) | datetime.datetime(2014, 1, 2, 3, 4, 6) |
datetime(2014,1,2,3,4,5) + timedelta(milliseconds=1) | datetime.datetime(2014, 1, 2, 3, 4, 5, 1000) |
datetime(2014,1,2,3,4,5) + timedelta(microseconds=1) | datetime.datetime(2014, 1, 2, 3, 4, 5, 1) |
from datetime import datetime, timedelta
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5) | datetime.datetime(2014, 1, 2, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(weeks=-1) | datetime.datetime(2013, 12, 26, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(days=-1) | datetime.datetime(2014, 1, 1, 3, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(hours=-1) | datetime.datetime(2014, 1, 2, 2, 4, 5) |
datetime(2014,1,2,3,4,5) + timedelta(minutes=-1) | datetime.datetime(2014, 1, 2, 3, 3, 5) |
datetime(2014,1,2,3,4,5) + timedelta(seconds=-1) | datetime.datetime(2014, 1, 2, 3, 4, 4) |
datetime(2014,1,2,3,4,5) + timedelta(milliseconds=-1) | datetime.datetime(2014, 1, 2, 3, 4, 4, 999000) |
datetime(2014,1,2,3,4,5) + timedelta(microseconds=-1) | datetime.datetime(2014, 1, 2, 3, 4, 4, 999999) |
from datetime import datetime
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5).year | 2014 |
datetime(2014,1,2,3,4,5).month | 1 |
datetime(2014,1,2,3,4,5).day | 2 |
datetime(2014,1,2,3,4,5).hour | 3 |
datetime(2014,1,2,3,4,5).minute | 4 |
datetime(2014,1,2,3,4,5).second | 5 |
from datetime import datetime
commander | résultat | Supplément |
---|---|---|
datetime(2014,1,2,3,4,5).strftime('%Y/%m/%d %H:%M:%S') | 2014/01/02 03:04:05 | |
datetime(2014,1,2,3,4,5).strftime('%Y') | 2014 | Année |
datetime(2014,1,2,3,4,5).strftime('%y') | 14 | Année(2 derniers chiffres) |
datetime(2014,1,2,3,4,5).strftime('%m') | 01 | Mois |
datetime(2014,1,2,3,4,5).strftime('%d') | 02 | journée |
datetime(2014,1,2,3,4,5).strftime('%H') | 03 | Temps(Notation sur 24 heures) |
datetime(2014,1,2,3,4,5).strftime('%I') | 03 | Temps(Notation de 12 heures) |
datetime(2014,1,2,3,4,5).strftime('%M') | 04 | Minutes |
datetime(2014,1,2,3,4,5).strftime('%S') | 05 | Secondes |
datetime(2014,1,2,3,4,5).strftime('%b') | Jan | Nom court du mois |
datetime(2014,1,2,3,4,5).strftime('%B') | January | Nom du mois |
datetime(2014,1,2,3,4,5).strftime('%a') | Thu | Nom court du jour |
datetime(2014,1,2,3,4,5).strftime('%A') | Thursday | Nom du jour |
datetime(2014,1,2,3,4,5).strftime('%p') | AM | AM or PM |
datetime(2014,1,2,3,4,5).isoformat() | 2014-01-02T03:04:05 | Format ISO 8601 |
datetime(2014,1,2,3,4,5).ctime() | Thu Jan 2 03:04:05 2014 | %a %b %d %X %Y |
datetime(2014,1,2,3,4,5).strftime('%c') | Thu Jan 2 03:04:05 2014 | %a %b %d %X %Y |
datetime(2014,1,2,3,4,5).strftime('%x') | 01/02/14 | %m/%d/%y |
datetime(2014,1,2,3,4,5).strftime('%X') | 03:04:05 | %H:%M:%S |
datetime(2014,1,2,3,4,5).strftime('%s') | 1388599445 | unixtime |
from datetime import datetime
commander | résultat |
---|---|
datetime.strptime('2014-01-02 03:04:05', '%Y-%m-%d %H:%M:%S') | datetime.datetime(2014, 1, 2, 4, 3, 5) |
from datetime import datetime
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5).strftime('%s') | 1388599445 |
from datetime import datetime
commander | résultat |
---|---|
datetime.fromtimestamp(1388599445) | datetime.datetime(2014, 1, 2, 4, 3, 5) |
from datetime import datetime
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5).date() | datetime.date(2014, 1, 2) |
from datetime import datetime
commander | résultat |
---|---|
datetime(2014,1,2,3,4,5).time() | datetime.time(3, 4, 5) |
Recommended Posts