Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python time now other timezone

#as an aware datetime
from datetime import datetime, timezone

utc_dt = datetime.now(timezone.utc) # UTC time
dt = utc_dt.astimezone() # local time


#or from pytz database
import pytz

tz = pytz.timezone('Europe/Berlin')
berlin_now = datetime.now(tz)
Comment

get local timezone python

import datetime

now = datetime.datetime.now()
local_now = now.astimezone()
local_tz = local_now.tzinfo
local_tzname = local_tz.tzname(local_now)
print(local_tzname)
Comment

localize timezone python

import pytz
from datetime import datetime

tz = pytz.timezone('Asia/Kathmandu')
datetime = datetime.now()
new_date = tz.localize(datetime)
Comment

how to get timezone in python

from time import gmtime, strftime
print(strftime("%z", gmtime()))
Comment

Handling timezone in Python

from datetime import datetime
import pytz

local = datetime.now()
print("Local:", local.strftime("%m/%d/%Y, %H:%M:%S"))


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

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

PREVIOUS NEXT
Code Example
Python :: make dataframe from list of tuples 
Python :: using bs4 to obtain html element by id 
Python :: import matplotlib.pyplot as plt 
Python :: how to play sound after pressing a button in tkinter 
Python :: python discord webhook 
Python :: tkinter boilerplate 
Python :: How do I mock an uploaded file in django? 
Python :: python deep copy of a dictionary 
Python :: read json file python utf8 
Python :: python datetime now minus 3 hours 
Python :: check if number is power of 2 python 
Python :: tkinter navigate pages 
Python :: how to get distinct value in a column dataframe in python 
Python :: python RuntimeWarning: overflow encountered in long_scalars 
Python :: python setup.py bdist_wheel did not run successfully 
Python :: django reverse 
Python :: easiest way to position labels in tkinter 
Python :: discord.py play mp3 file 
Python :: get attribute in selenium python 
Python :: python plot lines with dots 
Python :: install python 3.6 mac brew 
Python :: django import model from another app 
Python :: python read file 
Python :: get text between two strings python 
Python :: get columns based on dtype pandas 
Python :: how to change button background color while clicked tkinter python 
Python :: python program that takes command line arguments as input and print the number of arguments 
Python :: python os output to variable 
Python :: get current working directory python 
Python :: sns lineplot title 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =