Import time in Python(1)
what is python module ?
Python's time module provides a function for getting local time from the number of seconds elapsed since the epoch called localtime() .Since DST matters with local time, tm_isdst will change between 0 and 1 depending on whether or not DST is applicable for the given time.
From time module we can also stuck time for some time
Here I have some (import
time) codes:
Progam 1:
1-import time
2-Take variable T which is equal to time.localtime()
time.localtime can prite the current time of your device
3-Take Another variable currentTime which is equal to time.strftime
then ("%H:%M:%S",T) ( %H=hours,%M=minutes,%s=seconds)
time.strftime is use to define format
4-print (current time)
2-Take variable T which is equal to time.localtime()
time.localtime can prite the current time of your device
3-Take Another variable currentTime which is equal to time.strftime
then ("%H:%M:%S",T) ( %H=hours,%M=minutes,%s=seconds)
time.strftime is use to define format
4-print (current time)
Code:
import time T = time.localtime() currentTime = time.strftime("%H:%M:%S",T) print(currentTime) |
Output:
23:50:49 |
Progam 2:
1-From datetime import * (* mean hole library)
2-pytz mean python timezone
3-Take any variable suppose (a) which is equal to
pytz.timezome(“Aisa/Karachi”)
4-Take Another variable which is equal to datetime.now(a)5-print("PAKISTAN STANDARD
TIME: ", datetime_PAKISTAN.strftime("%H:%M:%S"))
Code:
from datetime import * import pytz a =
pytz.timezone("Asia/Karachi") datetime_PAKISTAN =
datetime.now(a) print("PAKISTAN
STANDARD TIME: ", datetime_PAKISTAN.strftime("%H:%M:%S")) |
Output:
PAKISTAN STANDARD TIME: 00:21:30 |
Time stuck in python
As we stuck time in python from import timeso here is the code for stuck time in pythonCode:import timeprint("Name : Najwa")time.sleep(4)print("Class : 12")time.sleep(4)print("Age : 18")Output:Name : Najwa (after 4 seconds)Class : 12 (after 4 seconds)Age : 18
time.sleep(4)
print("Age : 18")