Announcement

Collapse
No announcement yet.

Julian to ISO

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Julian to ISO

    How do we convert a stored Julian date back to a normal redable date, I have searched and most are ToJulian functions and the only one I could find for Julian to date send me to a page what confused the **** out of me, I just need to convert Julian to ISO, anyone know a easy way to do this?

    What I am trying to do is store it in to sqlite3 and use the date option to sort them, and when I pull them the end user needs to be able to read this and no standad user would know what a Julian time stamp was let alone read it and know witch is the one they wanted.

    I bashing my head here, could someone give us a hand, thanks.
    Plugins or Sources MokoX
    BunnyHop 2021 Here

  • #2
    I have been digging and one lib had this function in and it works for me

    Code:
    function Julian2Gregorian(jd)
    	intgr = Math.Floor(jd)
    	frac = jd - intgr
    	gregjd = 2299161
    
    	if(intgr >= gregjd) then
      		tmp = Math.Floor(((intgr - 1867216) - 0.25) / 36524.25)
      		j1 = intgr + 1 + tmp - Math.Floor(0.25*tmp)
    	else
      		j1 = intgr
    	end
    
    	--correction for half day offset
    	dayfrac = frac + 0.5
    	if(dayfrac >= 1.0) then
      		dayfrac = dayfrac - 1
      		j1 = j1 + 1
    	end
    
    	j2 = j1 + 1524
    	j3 = Math.Floor(6680.0 + ((j2 - 2439870) - 122.1)/365.25)
    	j4 = Math.Floor(j3*365.25)
    	j5 = Math.Floor((j2 - j4)/30.6001)
    
    	d = Math.Floor(j2 - j4 - Math.Floor(j5*30.6001))
    	m = Math.Floor(j5 - 1)
    	if(m > 12) then
      		m = m -12
    	end
    	y = Math.Floor(j3 - 4715)
    	if(m > 2) then
      		y = y -1
    	end
    	if(y <= 0) then
      		y = y - 1
    	end
    
    	if(y < 0) then
      		y = -y
    	end
    	return y .. "-" .. m .. "-" .. d
    end
    Only thing you need to change is

    return y .. "-" .. m .. "-" .. d
    to fit where ever you are, or return them as a table and then set it the string yourself later.
    Plugins or Sources MokoX
    BunnyHop 2021 Here

    Comment


    • #3
      I have found a problem, I don't have the time included in this, what would be the best way to include the time in to Julian and then convert it to Date and time
      Plugins or Sources MokoX
      BunnyHop 2021 Here

      Comment

      Working...
      X