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
170 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
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,440 points
1,773 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,140 points
1,092 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
282 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,780 points
1,804 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
179 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
235 views