python clock code example
Example 1: how to create clock in python
import sys
from tkinter import *
import time
def times():
current_time=time.strftime("%H:%M:%S")
clock.config(text=current_time)
clock.after(200,times)
root=Tk()
root.geometry("500x250")
clock=Label(root,font=("times",50,"bold"),bg="black",fg='blue')
clock.grid(row=2,column=2,pady=25,padx=100)
times()
digi=Label(root,text="Digital clock",font="times 24 bold",fg="violet")
digi.grid(row=0,column=2)
nota=Label(root,text="hours minutes seconds ",font="times 15 bold")
nota.grid(row=3,column=2)
root.mainloop()
Example 2: python clock
import datetime
import time
def clock():
while True:
print(datetime.datetime.now().strftime("%H:%M:%S"), end="\r")
time.sleep(1)
clock()
Example 3: time.strftime
from datetime import datetime
timestamp = 1528797322
date_time = datetime.fromtimestamp(timestamp)
print("Date time object:", date_time)
d = date_time.strftime("%m/%d/%Y, %H:%M:%S")
print("Output 2:", d)
d = date_time.strftime("%d %b, %Y")
print("Output 3:", d)
d = date_time.strftime("%d %B, %Y")
print("Output 4:", d)
d = date_time.strftime("%I%p")
print("Output 5:", d)
Example 4: python time library
import time
now = time.time()
print(now)