

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get computer's UTC offset in Python?
The computer's UTC offset is the timezone set on your computer. YOu can get this timezone information using the time module. time.timezone returns UTC offset in seconds.
For example
import time print(-time.timezone) # India's timezone: +5:30
Output
This will give the output −
19800
You can also use other workarounds to get the timezone information. You can create datetime objects for UTC and local timezones and subtract them and finally get the difference to find the timezone.
For example
import time from datetime import datetime ts = time.time() utc_offset = (datetime.fromtimestamp(ts) - datetime.utcfromtimestamp(ts)).total_seconds()
Output
This will give the output −
19800
- Related Questions & Answers
- Python Pandas - Get the UTC Offset Time
- How to make MySQL's NOW() and CURDATE() functions use UTC?
- How to convert pandas offset to Python date?
- How do I convert a datetime to a UTC timestamp in Python?
- Python Pandas - Get the weekmask applied on the CustomBusinessDay offset
- Python Pandas - Get the weekmask applied on the CustomBusinessHour offset
- How do you convert a JavaScript date to UTC?
- How to get full path of current file's directory in Python?
- How to get hour, minutes and seconds in android using offset time API class?
- How to get offsetdatetime local date in android using offset date time API class?
- How to use OFFSET in Android sqlite?
- How to get today's date in Java8?
- How to get yesterday’s date in JavaScript?
- Java Program to convert LocalDate to java.util.Date in UTC
- Python program to get all subsets having sum s\n
Advertisements