python datetime tutorial with examples
Tutorial Python DateTime:
Nel nostro precedente tutorial, abbiamo discusso Concetto di Python OOPs in dettaglio.
Abbiamo imparato di più su classe, oggetti, costruttore e oops insieme ai diversi pilastri di oops come ereditarietà, sovraccarico, sovrascrittura e occultamento dei dati supportati da Python.
In questo tutorial discuteremo un concetto aggiuntivo di Python che è Python DateTime. Leggi il nostro Serie di tutorial su Python per una migliore comprensione dei concetti di Python in dettaglio.
alternativa gratuita ai libri rapidi per le piccole imprese
Cosa imparerai:
Guarda il VIDEO Tutorial
Uno sguardo dettagliato a Python DateTime:
Python DateTime
In Python, date, time e DateTime sono classi integrate che ci forniscono una serie di funzioni integrate per gestire DateTime.
Queste funzioni vengono utilizzate per ottenere la data, l'ora e il giorno correnti.
Vediamo alcuni degli esempi per tutto quanto sopra.
Esempio 1:
from datetime import date def test_date(): today = date.today() print(“Today’s date is”, today) test_date()
Produzione:
La data di oggi è il 29/09/2018
Produzione:
Esempio 2:
from datetime import date def test_date(): today = date.today() #To print individual date componets print(“Date components are:”, today.day, today.month, today.year) test_date()
Produzione:
I componenti della data sono: 29 9 2018
Produzione:
Esempio 3:
come aprire i file .jnlp in Windows 10
from datetime import date def test_date(): today = date.today() #To print the weekday number(0=Monday , 6=Sunday) print(“Weekday number is:”, today.weekday()) test_date()
Produzione:
Il numero del giorno della settimana è: 5
Produzione:
Esempio 4:
from datetime import datetime def test_date(): today = datetime.now() #Print the curren date and time print(“Current date and time is:”, today) test_date()
Produzione:
La data e l'ora correnti sono: 2018-09-29 21:26: 09.578260
Produzione:
software per punti vendita per ipad
Esempio 5:
from datetime import datetime def test_date(): time = datetime.time(datetime.now()) #to retrieve the current time print(“Current time is:”, time) test_date()
Produzione:
L'ora corrente è: 21: 28: 32.980759
Produzione:
Formattazione di data e ora utilizzando il metodo strftime ()
Esempio 6:
import datetime print(“Current date and time is:”, datetime.datetime.now()) print(“Current date and time using strftime method:”, datetime.datetime.now().strftime(“%y-%m-%d-%H-%M”) print(“Current year is:”, datetime.date.today().strftime(“%Y”)) print(“Month of year is:”, datetime.date.today().strftime(“%B”)) print(“Week number of the year is:”, datetime.date.today().strftime(“%W”)) print(“Weekday of the week is:”, datetime.date.today().strftime(“%w”)) print(“Day of the year is:”, datetime.date.today().strftime(“%j”)) print(“Day of the month is:”, datetime.date.today().strftime(“%d”)) print(“Day of the week is:”, datetime.date.today().strftime(“%A”))
Produzione :
La data e l'ora correnti sono: 2018-09-29 21:32: 30.643372
Data e ora correnti utilizzando il metodo strftime: 18-09-29-21-32
L'anno in corso è: 2018
Il mese dell'anno è: Settembre
Il numero della settimana dell'anno è: 39
Il giorno della settimana della settimana è: 6
Il giorno dell'anno è: 272
Il giorno del mese è: 29
Il giorno della settimana è: sabato
Produzione:
Conclusione
In questo tutorial abbiamo discusso alcuni degli argomenti aggiuntivi delle funzioni incorporate di stringhe e altri concetti come l'apertura e l'eliminazione di un file e i metodi integrati forniti da DateTime in dettaglio.
Il nostro prossimo tutorial spiegherà in dettaglio le funzioni delle stringhe di Python !!
Tutorial PREV | PROSSIMO Tutorial
Lettura consigliata
- Funzioni stringa Python
- Tutorial Python per principianti (formazione pratica GRATUITA su Python)
- Tutorial approfonditi su Eclipse per principianti
- Tutorial sulle funzioni principali di Python con esempi pratici
- Tutorial Python String Split
- Funzioni Python
- Variabili Python
- Python Tuple Tutorial con esempi pratici