Git Product home page Git Product logo

Comments (3)

marcinpr avatar marcinpr commented on August 22, 2024

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.

kylebarron avatar kylebarron commented on August 22, 2024

I don't know; timezones are hard! If you'd like to improve the docs, a PR is welcome

from suncalc-py.

Bliph avatar Bliph commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.