Python časový modul datetime

Príklady kódu

15
0

python datetime teraz

import datetime
print(datetime.datetime.now()) #datetime.datetime.now() is the syntax 
10
0

python formát času

The program below converts a datetime object containing current date and time to different string formats.

Code:
  
from datetime import datetime

now = datetime.now() # current date and time

year = now.strftime("%Y")
print("year:", year)

month = now.strftime("%m")
print("month:", month)

day = now.strftime("%d")
print("day:", day)

time = now.strftime("%H:%M:%S")
print("time:", time)

date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
print("date and time:",date_time)	

Output after run the code:
year: 2020
month: 03
day: 31
time: 04:59:31
date and time: 03/31/2020, 04:59:31
      
Here, year, day, time and date_time are strings, whereas now is a datetime object.

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................