Python časovej triedy

Príklady kódu

20
0

knižnica času python

#also see datetime
import time
now = time.time()
print(now)
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.
7
0

časový modul v Pythone

import time
seconds = time.time()
print("Seconds since epoch =", seconds)	
0
0

python časová metóda

from time import sleep, time

start = time()
sleep(2)
print(format(time() - start, '.3f'), 's', sep='') # 2.003s
0
0

čas python

#import time module:
import time
#module has various attributes: 
dir(time)
[..., 'localtime', 'mktime', 'sleep', 'sleep_ms', 'sleep_us', 'ticks_add', 'ticks_cpu', 'ticks_diff', 'ticks_ms', 'ticks_us', 'time']

#default expression is in seconds with zero being start of runtime
secFromStart = time.time()

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
..................................................................................................................