9 Replies Latest reply on Apr 2, 2009 5:58 AM by rahimhaji

    Gregorian to julian

    rahimhaji Level 1
      Dear Friends,

      i have data (date of creation , time stamp) in SQLite. it is in julian format. i need to compare it with sytem time. pls tell me

      1) how to convert the gregorian datetime into julian

      2) how to convert the julian datetiem into gregorian format.

      for example: 2454922.819548611 (julian) which is equal to Wednesday, April 01, 2009 7:40 AM . pls tell me how to conver this formats. like this text format to number format.

      i got struct up. Pls help me..

      Thanks and Regards,

      Syed Abdul Rahim
        • 1. Re: Gregorian to julian
          rahimhaji Level 1
          dear friends,

          or atleast tell me, how to convert the April 01, 2009 7:40 AM in to 2454922.819548611.

          Thanks and Regards,
          Syed Abdul Rahim
          • 2. Re: Gregorian to julian
            Richard_Abbott Level 3
            Syed Abdul Rahim,
            according to http://aa.usno.navy.mil/data/docs/JulianDate.php, "Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE".
            The Flex Date class has a method valueOf():Number, which returns the number of milliseconds since midnight January 1, 1970, universal time, for a Date object.
            Now according to the above site, the Julian date for CE 1970 January 1 00:00:00.0 UT is JD 2440587.50000, so given these bits of info you should be able to write a function that turns one into the other.

            Going the other way, the Date() constructor has several overloads, one of which says "If you pass one argument of data type Number, the Date object is assigned a time value based on the number of milliseconds since January 1, 1970 0:00:000 GMT, as specified by the lone argument." Once you have the date object, you can format it however you like.
            Hope that helps,
            Richard
            • 3. Re: Gregorian to julian
              rahimhaji Level 1
              Dear Friends,

              any body can help me to convert a date from our system to julian. for example i want to convert April 01, 2009 7:40 AM (system time )in to 2454922.819548611 (julian). Is ther any function or command. i refered so many atricles. all the calculations let me a wrong result. pls help me to provide a function to convert this date in to equivalent julian number. i got struct up. i need to finish my project ...pls

              Thanks and Regards,
              Syed Abdul Rahim
              • 4. Re: Gregorian to julian
                Richard_Abbott Level 3
                Syed Abdul Rahim,
                are you taking account of the difference between your system time and UTC?
                Richard
                • 5. Re: Gregorian to julian
                  rahimhaji Level 1
                  Dear Richard,

                  Thaks for ur response. Actually iam working on a ticker created in Flex. i want to insert alert option. i mean if the RSS feed is updated, the latest news has to come as alert. for that. i want to compare the system time and the time of creation (timestamp) and show the alert. already the data is stored as julian time 2454922.819548611. if i fetch from system time or server time it comes as April 01, 2009 7:40 AM (if i use setTime option it wil be 1238588097481) like tihis, i want to compare hw can i do that? for that i need to convert the actualy time to julian time.

                  pls help me. iam following the snackr open souce to create the ticker.

                  Thanks and Regards,
                  Syed Addul Rahim
                  • 6. Re: Gregorian to julian
                    rahimhaji Level 1

                    Dear Richard,

                    Thaks for ur response. Actually iam working on a ticker created in Flex. i want to insert alert option. i mean if the RSS feed is updated, the latest news has to come as alert. for that. i want to compare the system time and the time of creation (timestamp) and show the alert. already the data is stored as julian time 2454922.819548611. if i fetch from system time or server time it comes as April 01, 2009 7:40 AM (if i use setTime option it wil be 1238588097481) like tihis, i want to compare hw can i do that? for that i need to convert the actualy time to julian time.

                    pls help me. iam following the snackr open souce to create the ticker.

                    Thanks and Regards,
                    Syed Addul Rahim
                    • 7. Re: Gregorian to julian
                      Richard_Abbott Level 3
                      Syed Addul Rahim,
                      I don't know if you saw the reply I posted earlier today (just before 8am UK time!) in which I mentioned variuios methods in the Date class that might help you?
                      Richard
                      • 8. Re: Gregorian to julian
                        rahimhaji Level 1
                        Dear Mr.Richard,

                        Thaks a lot, iam trying that one also. i did not got any .. thks

                        Regards,
                        Syed Abdul Rahim
                        • 9. Re: Gregorian to julian
                          rahimhaji Level 1
                          hi friends,

                          if found the way to convert calender date time to Julian..

                          // convert Julian date to calendar date
                          // (algorithm adopted from Press et al.)
                          //-----------------------------------------------------------------------------
                          function jd_to_cal(jd)
                          {
                          var j1, j2, j3, j4, j5; //scratch

                          //
                          // get the date from the Julian day number
                          //
                          var intgr = Math.floor(jd);
                          var frac = jd - intgr;
                          var gregjd = 2299161;
                          if( intgr >= gregjd ) { //Gregorian calendar correction
                          var tmp = Math.floor( ( (intgr - 1867216) - 0.25 ) / 36524.25 );
                          j1 = intgr + 1 + tmp - Math.floor(0.25*tmp);
                          } else
                          j1 = intgr;

                          //correction for half day offset
                          var dayfrac = frac + 0.5;
                          if( dayfrac >= 1.0 ) {
                          dayfrac -= 1.0;
                          ++j1;
                          }

                          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 );

                          var d = Math.floor(j2 - j4 - Math.floor(j5*30.6001));
                          var m = Math.floor(j5 - 1);
                          if( m > 12 ) m -= 12;
                          var y = Math.floor(j3 - 4715);
                          if( m > 2 ) --y;
                          if( y <= 0 ) --y;

                          //
                          // get time of day from day fraction
                          //
                          var hr = Math.floor(dayfrac * 24.0);
                          var mn = Math.floor((dayfrac*24.0 - hr)*60.0);
                          var f:Number = ((dayfrac*24.0 - hr)*60.0 - mn)*60.0;
                          var sc = Math.floor(f);
                          f -= sc;
                          if( f > 0.5 ) ++sc;
                          if( sc == 60 ) {
                          sc = 0;
                          ++mn;
                          }
                          if( mn == 60 ) {
                          mn = 0;
                          ++hr;
                          }
                          if( hr == 24 ) {
                          hr = 0;
                          ++d; //this could cause a bug, but probably will never happen in practice
                          }

                          if( y < 0 )
                          y = -y;

                          trace("y = " + y);
                          trace("m = " + m);
                          trace("d = " + d);
                          trace("hr = " + hr);
                          trace("mn = " + mn);
                          trace("sc = " + sc);
                          }

                          jd_to_cal(2454924.20414);

                          i hope this will be helpful for some body.

                          Thanks and Regards,
                          Syed Abdul Rahim