Import time in Python(1)
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.
Here I have some (import
time) codes:
Progam 1:
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:
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 |
