Library (julian), lack of usage information - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Library (julian), lack of usage information (/thread-16518.html) Pages:
1
2
|
RE: Library (julian), lack of usage information - snippsat - Mar-03-2019 (Mar-03-2019, 04:32 PM)samsonite Wrote: No, because of the unnecessary import pendulum.I did post a solution with datetime and strptime before in Thread. >>> import datetime >>> import julian >>> >>> dt_str = '2018-09-09 12:12:12.005876' >>> dt = datetime.datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S.%f") >>> julian.to_jd(dt, fmt='jd') 2458371.0084722904Pendulum works just like daytime,just with a lot of improvements like eg i use parse of dates strings.Quote:Drop-in replacement for the standard datetime class. If libraries over time show that they are much better than what's is standard library, i will recommenced that,like eg Requests over urllib and many more. RE: Library (julian), lack of usage information - samsonite - Mar-04-2019 Oh yes, snippsat! It's what I was looking for, fantastic! Get a glance to the comments below. Thanks again and cheers # ------- jul_final.py ---------- import datetime import julian dt_str = '2018-09-09 12:12:12.005876' dt = datetime.datetime.strptime(dt_str, "%Y-%m-%d %H:%M:%S.%f") mjd= julian.to_jd(dt, fmt='jd') - 2400000.5 print(mjd) # ------- OUTPUT --------- # C:\Training>python jul_final.py # 58370.508472290356 # ------- EXPECTED -------- # Given date and time as follows # 2018-09-09 12:12:12.005876 (time accurate to 6 decimal places) # find # MJD 58370.50847229023 # -------------------------- # My comments: the (julian) algorithm is highly performant # Delta= (.50847229036-.50847229023) = 13e-11 days # -------------------------------------------------------- RE: Library (julian), lack of usage information - samsonite - Mar-04-2019 Slight amendment of one of my previous posts. Cheers # ------- jul1bis.py -------- import julian import datetime mjd = 58370.5084722222 dt = julian.from_jd(mjd, fmt='mjd') print(dt) # mjd2 = julian.to_jd(dt + datetime.timedelta(hours=0), fmt='jd') - 2400000.5 print(mjd2) # ------- OUTPUTS ----------- # C:\Training>python jul1bis.py # 2018-09-09 12:12:12.000012 # 58370.50847222237 # My comments: line 8 been amended with (hours=0, scaletime of MJD), # so the back calculated (mjd2) fully matches (mjd) of line 4 # ------------------------------------------------------------------- |