table de référence rapide du format datetime python

Article associé

mémo d'installation python (pyenv)

datetime

# -*- coding:utf-8 -*-
import datetime
from datetime import date,timedelta

#Date et heure actuelles
d = datetime.date.today() # 2019-08-01
print(d.strftime("%Y%m%d")) # 20190801
 
#Date de référence
d = date(2019, 8, 01) # 2019-08-01
#Le jour d'avant
yesterday = d - timedelta(days=1) # 2019-07-31
#Il y a 20 jours
before_20_days = d - timedelta(days=1) * 20 # 2019-07-12
#Il y a 40 jours
before_40_days = d - timedelta(days=40) # 2019-06-22
#Il y a 2 semaines
two_weeks_ago = d + timedelta(weeks=-2) # 2019-07-18

Graphique simplifié

Code Meaning Example
%a Weekday as locale’s abbreviated name. Mon
%A Weekday as locale’s full name. Monday
%w Weekday as a decimal number, where 0 is Sunday and 6 is Saturday. 1
%d Day of the month as a zero-padded decimal number. 30
%-d Day of the month as a decimal number. (Platform specific) 30
%b Month as locale’s abbreviated name. Sep
%B Month as locale’s full name. September
%m Month as a zero-padded decimal number. 9
%-m Month as a decimal number. (Platform specific) 9
%y Year without century as a zero-padded decimal number. 13
%Y Year with century as a decimal number. 2013
%H Hour (24-hour clock) as a zero-padded decimal number. 7
%-H Hour (24-hour clock) as a decimal number. (Platform specific) 7
%I Hour (12-hour clock) as a zero-padded decimal number. 7
%-I Hour (12-hour clock) as a decimal number. (Platform specific) 7
%p Locale’s equivalent of either AM or PM. AM
%M Minute as a zero-padded decimal number. 6
%-M Minute as a decimal number. (Platform specific) 6
%S Second as a zero-padded decimal number. 5
%-S Second as a decimal number. (Platform specific) 5
%f Microsecond as a decimal number, zero-padded on the left. 0
%z UTC offset in the form +HHMM or -HHMM (empty string if the the object is naive).
%Z Time zone name (empty string if the object is naive).
%j Day of the year as a zero-padded decimal number. 273
%-j Day of the year as a decimal number. (Platform specific) 273
%U Week number of the year (Sunday as the first day of the week) as a zero padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0. 39
%W Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0. 39
%c Locale’s appropriate date and time representation. Mon Sep 30 07:06:05 2013
%x Locale’s appropriate date representation. 9/30/2013
%X Locale’s appropriate time representation. 7:06:05
%% A literal '%' character. %

[référence] http://strftime.org/ http://docs.python.jp/2/library/datetime.html

Recommended Posts

table de référence rapide du format datetime python
Tableau de référence rapide sous environnement Proxy
Tableau de référence rapide: collection de commandes liées aux disques Linux
Format de chaîne Python
format en python
À propos de la référence Python
Page de référence Python
expansion de variable python, format
Table de décalage Django Python
Format d'image en Python
Notes sur le format Python Pickle
Utilisation méthodique du format [Python]
conversion de date / heure <-> python unix-time
python> datetime> De la chaîne de date (format ISO: 2015-12-09 12:40:08) au type datetime
Python / datetime> Implémentation pour convertir le format AAAAMMJJ en AAAA / MM / JJ
Formatez facilement JSON avec Python
Indentation Python et format de chaîne
Python - Démarrage rapide de la journalisation
[Python] Boutique d'anguilles de table longue
À propos de la date et du fuseau horaire Python
[Python 2/3] Analyser la chaîne de format
Formater json avec Vim (avec python)
[Python] Référence Numpy, extraction, combinaison
Format de chaîne avec l'opérateur Python%
Python # À propos de la référence et de la copie
Python3> Fonctions> Table des symboles> Affecter aux variables / Variables de référence / Variables globales / globals () / locals ()