Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python Current time using time module

import time

t = time.localtime()
current_time = time.strftime("%H:%M:%S", t)
print(current_time)
Comment

time current time python time.time

time.time()
Comment

Python Current time using time module

from datetime import datetime
import pytz

tz_NY = pytz.timezone('America/New_York') 
datetime_NY = datetime.now(tz_NY)
print("NY time:", datetime_NY.strftime("%H:%M:%S"))

tz_London = pytz.timezone('Europe/London')
datetime_London = datetime.now(tz_London)
print("London time:", datetime_London.strftime("%H:%M:%S"))
Comment

local time in python

>>> import pytz
>>> from datetime import datetime, date, time
# To get the UTC time of current day (today) for a given time zone
# use the localize() function of the pytz. 
# The reason for this is that the localize() takes into account the Day Time Saving
# which niether the datetime constructors nor replace() account for.
# 
# To for example, the utc time of today in australia time zone:

import pytz
from datetime import datetime, date, time

# set time zone
tz = pytz.timezone("Australia/Melbourne")

# Get today's date in the current time zone (i.e local time)
todaydate = date.today() # you can also use date(2022, 2, 8)

# Get midnight of today (still local time)
# note time() without arguments will result to midnight

midnight_local = datetime.combine(todaydate, time())

print midnight_local

# convert this midnight datetime to the midnight datetime
# in the given time zone. In this case autralia time zone
austra_midnight = tz.localize(midnight_local)

print austra_midnight

# convert the midnight time in australia time zone to UTC
midnight_austra_utc = austra_midnight.astimezone(pytz.uct)

print midnight_austra_utc



# Ref:
# https://stackoverflow.com/questions/373370/how-do-i-get-the-utc-time-of-midnight-for-a-given-timezone
Comment

PREVIOUS NEXT
Code Example
Python :: python program for geometric progression 
Python :: how to loop through files in a directory python 
Python :: python scatter plot 
Python :: Python Time object to represent time 
Python :: Python program to remove duplicate characters of a given string. 
Python :: how to install library in python 
Python :: count line of code in python recursive 
Python :: pandas timedelta to seconds 
Python :: python make a shop menu 
Python :: most occurring string in column pandas 
Python :: python specify typeError output 
Python :: extract images from bag file python 
Python :: fizzbuzz python 
Python :: python create hash from string 
Python :: # load multiple csv files into dataframe 
Python :: pypi toml 
Python :: get all files of a drive folder to google colab 
Python :: how to create a cube in ursina 
Python :: update tupple in python 
Python :: python get ip info 
Python :: YouCompleteMe unavailable: requires Vim compiled with Python (3.6.0+) support. 
Python :: add day in date python 
Python :: display flask across network 
Python :: how to import PyMem python 
Python :: how many data types are specified to numeric values in python 
Python :: pandas read excel 
Python :: dataframe groupby to dictionary 
Python :: access dataframe column with space 
Python :: mish activation function tensorflow 
Python :: python string to xml 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =