Nội Dung Khóa Học

16: Hàm time python
About Lesson

Code :
import time
giay=time.time() # trả về số giây, tính từ 0:0:00 ngày 1/1/1970 theo giowgf utc , gọi là poch
t=time.ctime() #trả về thứ ngày tháng theo số giây
print(giay)
print(t)

#cách kiểm tra mốc
import time
h=time.ctime(0)
print(h)

# time.sleep() # delay chương trình thực thi , ví dụ về nhập mật khẩu delay 3s khóa cửa
#ví dụ time.sleep:
print(“vui lòng chờ 3s”)
hientai=time.ctime()
print(hientai)
time.sleep(3) # cho ngủ 3s
print(“Đã hết 3s “)
tuonglai=time.ctime()
print(tuonglai)

#hàm time.localtime()
thoigian3=time.localtime()
print(“năm hiện tại là “,thoigian3.tm_year) #trả về năm hiện tại, tháng, tuần …theo giờ địa phương
print(thoigian3)

Code :
nhap vao tuoi-cho bietnam 100 tuoi
import time
ten=input(“nhap vao ten: “)
tuoi=int(input(“nhap vao tuoi cua ban: “))
hientai=time.localtime()
print(hientai)
namhientai=hientai.tm_year
print(namhientai)
print(“Nam ban dat 100 tuoi la “, (100-tuoi)+namhientai )

Code : #Xuất
string time
import time
t=time.localtime()
print(t) # get thời gian hiện tại

time_string=time.strftime(“%m/%d/%y, %H:%M:%S “,t)
print(time_string)
print(type(time_string))