question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ts.utc(...) != ts.now() when utc set to now.

See original GitHub issue

Hi there, I love your work! This is an excellent python package. I have also found ephem and pyephem to be useful, though I’m not sure I understand the difference between them all. They all work well.

I am running the following:

from skyfield.api import load
import datetime, time, re

planets = load('de421.bsp')
earth, mercury = planets['earth'], planets['mercury']

ts = load.timescale()

t1 = datetime.datetime.now()
precise_second_t1 = float(t1.strftime("%-S.%f"))

t_now = ts.now()
t_utc_now = ts.utc(t1.year, t1.month, t1.day, t1.hour, t1.minute, precise_second_t1)

astrometric1 = earth.at(t_now).observe(mercury)
astrometric2 = earth.at(t_utc_now).observe(mercury)

ra1, dec1, distance1 = astrometric1.radec()
ra2, dec2, distance2 = astrometric2.radec()

print('RA for ts.now():\t', ra1)
print('RA for ts.utc(...):\t', ra2)

These should print the same, but they are not. I am wondering if you know why this might be?

Thank you again for such an amazing package!

Ever yours, Jake Ireland.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
brandon-rhodescommented, Feb 27, 2020

Correct! The now() routine does not attach a timezone. I’m glad you have the date working correctly now in your script, and, yes, hopefully if anyone else is confused that datetime.now() does not return UTC, they will find this issue in a web search and learn about the difference.

0reactions
jakewilliamicommented, Feb 27, 2020

Ahh, I see. That does indeed work, thank you! So to clarify before we close the “issue”, datetime.datetime.now() lacks time zone information that datetime.datetime.utcnow()? Sorry to open an issue that wasn’t actually an issue. Hopefully this will help someone as naïve as myself in the future…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Date.UTC() - JavaScript - MDN Web Docs
UTC() takes comma-delimited date and time parameters and returns the number of milliseconds between January 1, 1970, 00:00:00, universal time ...
Read more >
How to convert a Date to UTC? - Stack Overflow
First, you must think of all Dates/Times as already being UTC with a timezone modifier for display purposes. Again, browsers may differ, however,...
Read more >
Get the current Date and Time in UTC using JavaScript
Use the toUTCString() method to get the current date and time in utc, e.g. new Date().toUTCString() . The toUTCString method converts a date ......
Read more >
UTC Time Now
UTC current date is 22nd Thursday December 2022. UTC: Coordinated Universal Time. About UTC Time.
Read more >
Dates and Time — Skyfield documentation - Rhodes Mill
from skyfield.api import load # Asking the current date and time ts = load.timescale() t = ts.now() print(t.utc_jpl()). A.D. 2015-Oct-11 10:00:00.0000 UTC ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found