python datetime tutorial with examples
Tutorial Python DateTime:
În tutorialul nostru anterior, am discutat Conceptul Python OOPs detaliat.
Am aflat mai multe despre clasă, obiecte, constructor și oops împreună cu diferiții stâlpi de oops, cum ar fi Moștenirea, suprasolicitarea, suprascrierea și ascunderea datelor care sunt susținute de Python.
În acest tutorial vom discuta despre un concept suplimentar de python, care este Python DateTime. Citiți prin intermediul nostru Seria de tutoriale Python pentru o mai bună înțelegere a conceptelor Python în detaliu.
software-ul DVD rip and burn gratuit
Ce veți învăța:
Urmăriți Tutorialul VIDEO
O privire detaliată asupra Python DateTime:
Python DateTime
În Python, data, ora și DataTime sunt clase încorporate care ne oferă o serie de funcții încorporate pentru a face față DateTime.
Aceste funcții sunt utilizate pentru a obține data, ora și ziua curente.
Să vedem câteva exemple pentru toate cele de mai sus.
Exemplul 1:
from datetime import date def test_date(): today = date.today() print(“Today’s date is”, today) test_date()
Ieșire:
Data de astăzi este 29-09-2018
Ieșire:
Exemplul 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()
Ieșire:
Componentele datei sunt: 29 9 2018
Ieșire:
Exemplul 3:
cum rulez un fișier jar în 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()
Ieșire:
Numărul zilei săptămânii este: 5
Ieșire:
Exemplul 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()
Ieșire:
Data și ora actuală sunt: 2018-09-29 21: 26: 09.578260
Ieșire:
Exemplul 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()
Ieșire:
cea mai bună aplicație de spionaj pentru Android
Ora curentă este: 21: 28: 32.980759
Ieșire:
Formatarea datei și orei folosind metoda strftime ()
Exemplul 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”))
Ieșire :
Data și ora curente sunt: 2018-09-29 21: 32: 30.643372
Data și ora curente folosind metoda strftime: 18-09-29-21-32
Anul curent este: 2018
Luna anului este: septembrie
Numărul săptămânii al anului este: 39
Ziua săptămânii a săptămânii este: 6
Ziua anului este: 272
Ziua lunii este: 29
Ziua săptămânii este: sâmbătă
Ieșire:
Concluzie
În acest tutorial am discutat câteva dintre subiectele suplimentare ale funcțiilor încorporate în șiruri și alte concepte precum deschiderea și ștergerea unui fișier și metodele încorporate furnizate de DateTime în detaliu.
Următorul nostru tutorial va explica în detaliu funcțiile Python String !!
Lectură recomandată
- Funcții Python String
- Tutorial Python pentru începători (Training gratuit Python GRATUIT)
- Tutoriale detaliate pentru eclipsă pentru începători
- Tutorial de funcții principale Python cu exemple practice
- Tutorial Python String Split
- Funcții Python
- Variabile Python
- Tutorial Python Tuple cu exemple practice