Comments (3)
I have found a solution to my question from the last sentence:
sunrise_aware = pytz.timezone('UTC').localize(suncalc.get_times(date, lon, lat)['sunrise'])
print(sunrise_aware.astimezone().strftime("%H:%M:%S %Z"))
Is there any simpler solution?
from suncalc-py.
I don't know; timezones are hard! If you'd like to improve the docs, a PR is welcome
from suncalc-py.
I do not know if this is "simpler", but I always like to keep timestamps in epoch. After all, this is just a number.
from datetime import datetime, timezone
import time
from suncalc import get_position, get_times
lon = 7.0
lat = 58.0
# Get "today"
utc_now = datetime.fromtimestamp(time.time(), timezone.utc)
# Extract sunrise "today"
solar_times = get_times(date=utc_now, lng=lon, lat=lat)
# Extract sunrise epoch [s]
ts_sunrise_epoch = solar_times.get("sunrise").timestamp()
# Convert to local timezone
local_zone = datetime.now().astimezone().tzinfo
ts_sunrise_local = datetime.fromtimestamp(ts_sunrise_epoch, local_zone)
print(ts_sunrise_local.isoformat())
from suncalc-py.
Related Issues (12)
- Missing CHANGELOG.md HOT 1
- Vectorisation all casts to same datetime HOT 1
- RuntimeWarning: invalid value encountered in arccos HOT 3
- DataFrame argument returns wrong solar positions HOT 2
- Moon Illumination Issue HOT 4
- Pandas NaT times cause unexpected behaviour HOT 1
- Receiving a "numpy.float64 object is not iterable" exception in from_julian when calling get_times() near the summer solstice HOT 5
- Email bug report
- arccos errors in 0.1.2 HOT 1
- Wrong annotations are misleading HOT 2
- lat-long vs long-lat && azimuth starting from South is just confusing HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from suncalc-py.