Is a specific timezone using DST right now

0 votes

How would I get my python script to check whether or not a specific timezone that is stored in a variable using DST right now? My server is set to UTC. For example, I have an instance:

zonename = Pacific/Wallis

I want to run the query about if it is using DST right now and have the reply come back as either true of false.

How do I do this?

Aug 9, 2019 in Python by ana1504.k
• 7,910 points
632 views

1 answer to this question.

0 votes

You can try the following;

from pytz import timezone
from datetime import datetime

zonename = "Pacific/Wallis"
now = datetime.now(tz=timezone(zonename))
dst_timedelta = now.dst()
### dst_timedelta is offset to the winter time, 
### thus timedelta(0) for winter time and timedelta(0, 3600) for DST; 
### it returns None if timezone is not set

print "DST" if dst_timedelta else "no DST"

an alternative is to use:

now.timetuple().tm_isdst 
answered Aug 9, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer

I have trained a model using machine learning algorithm in python , now i want to create a browser extension of that saved model , Is it possible ??

Hi@Shubham, It may possible. When you saved your ML ...READ MORE

answered Jun 13, 2020 in Python by MD
• 95,460 points
1,128 views
0 votes
1 answer

Is there anyway to obtain the full abstract from a 'PUBmed' article using bioPython

Hey Charlie, it's certainly possible to pull ...READ MORE

answered Aug 24, 2018 in Python by aryya
• 7,460 points
3,271 views
0 votes
1 answer

Is there a way of using .lower more effectively in tkinter?

Here is a simple function and some ...READ MORE

answered Sep 25, 2018 in Python by Priyaj
• 58,020 points
2,346 views
0 votes
1 answer
0 votes
1 answer

Does Python's time.time() return the local or UTC timestamp?

The time.time() function returns the number of seconds since ...READ MORE

answered Oct 5, 2018 in Python by SDeb
• 13,300 points
1,143 views
0 votes
1 answer

Does Python's time.time() return the local or UTC timestamp?

The time.time() function returns the number of seconds since ...READ MORE

answered Nov 14, 2018 in Python by charlie_brown
• 7,720 points
5,364 views
0 votes
2 answers
0 votes
1 answer

comparing strings in Python using "==" or "is"

is is used for identity testing and ...READ MORE

answered Sep 19, 2018 in Python by SDeb
• 13,300 points
840 views
0 votes
1 answer

Is there a string 'contains' in python?

In this case, you can use the ...READ MORE

answered Sep 25, 2018 in Python by SDeb
• 13,300 points
696 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP