Showing posts with label Time. Show all posts
Showing posts with label Time. Show all posts

Program to convert DateTime to string

import time

def convert(datetime_str):

datetime_str = time.mktime(datetime_str)

format = "%b %d %Y %r" 

dateTime = time.strftime(format, time.gmtime(datetime_str))

return dateTime

date_time = (2018, 12, 4, 10, 7, 00, 1, 48, 0)

print(convert(date_time))


Program to Create a Lap Timer

import time

starttime=time.time()

lasttime=starttime

lapnum=1

print("Press ENTER to count laps.\nPress CTRL+C to stop")

try:

while True:

input()

laptime=round((time.time() - lasttime), 2)

totaltime=round((time.time() - starttime), 2)

print("Lap No. "+str(lapnum))

print("Total Time: "+str(totaltime))

print("Lap Time: "+str(laptime))

print("*"*10)

lasttime=time.time()

lapnum+=1

except KeyboardInterrupt:

print("Done")


Program to find yesterday’s, today’s and tomorrow’s date

from datetime import datetime, timedelta

currentday = datetime.now()

yesterday = currentday - timedelta(1)

tomorrow = currentday + timedelta(1)

print("Yesterday = ", yesterday.strftime('%d-%m-%Y'))

print("Today = ", currentday.strftime('%d-%m-%Y'))

print("Tomorrow = ", tomorrow.strftime('%d-%m-%Y'))


Python program to find day of birth

import datetime
y = input("Enter year of Birth: ");
m = input("Enter month of Birth: ");
d = input("Enter date of Birth: ");
mydate = datetime.date(int(y),int(m),int(d))
print(mydate.strftime("%A"))