Nodejs Date Convert Date2Julian()

Here you can find the source of Date2Julian()

Method Source Code

var timer = function(){
   this.count = 1;//www . jav  a2  s  .  co  m
   this.multiplier = .25;
   return this;
}

Date.prototype.Date2Julian = function() {
   return Math.floor( ( this / 86400000 ) - ( this.getTimezoneOffset() / 1440 ) + 2440587.5 );
};

Number.prototype.Julian2Date = function() {

   var X = parseFloat(this)+0.5;
   var Z = Math.floor(X); //Get day without time
   var F = X - Z; //Get time
   var Y = Math.floor((Z-1867216.25)/36524.25);
   var A = Z+1+Y-Math.floor(Y/4);
   var B = A+1524;
   var C = Math.floor((B-122.1)/365.25);
   var D = Math.floor(365.25*C);
   var G = Math.floor((B-D)/30.6001);

   //must get number less than or equal to 12)
   var month = (G < 13.5) ? ( G - 1 ) : ( G - 13 );

   //if Month is January or February, or the rest of year
   var year = (month<2.5) ? (C-4715) : (C-4716);
   month -= 1; //Handle JavaScript month format
   var UT = B-D-Math.floor(30.6001*G)+F;
   var day = Math.floor(UT);

   //Determine time
   UT -= Math.floor(UT);
   UT *= 24;
   var hour = Math.floor(UT);
   UT -= Math.floor(UT);
   UT *= 60;
   var minute = Math.floor(UT);
   UT -= Math.floor(UT);
   UT *= 60;
   var second = Math.round(UT);

   return new Date(Date.UTC(year, month, day, hour, minute, second));
};

Related

  1. toYYYYMMDD()
    Date.prototype.toYYYYMMDD = function() {
        return this.getFullYear() + String(this.getMonth()+1).lpad(2, "0") + String(this.getDate()).lpad(2, "0");
    
  2. toYmdHis()
    Date.prototype.toYmdHis = function() {
        return this.getFullYear() + "-" + twoDigits(1 + this.getMonth()) + "-" + twoDigits(this.getDate()) + " " + twoDigits(this.getHours()) + ":" + twoDigits(this.getMinutes()) + ":" + twoDigits(this.getSeconds());
    };
    
  3. to_DMY()
    Date.prototype.to_DMY = function(){
        return Util.leadingzero(this.getDate()) + '/' + Util.leadingzero(this.getMonth() + 1) + '/' + this.getFullYear()
    };
    
  4. to_datetimepicker_format()
    Date.prototype.to_datetimepicker_format = function() {
        var Y = this.getUTCFullYear();
        var M = this.getUTCMonth() + 1;
        var D = this.getUTCDate();
        var h = this.getUTCHours();
        var m = this.getUTCMinutes();
        return Y + "-" + M.pad() + "-" + D.pad() + " " + h.pad() + ":" + m.pad();
    
  5. tojson()
    Date.prototype.tojson = function() {
        var UTC = Date.printAsUTC ? 'UTC' : '';
        var year = this['get'+UTC+'FullYear']().zeroPad(4);
        var month = (this['get'+UTC+'Month']() + 1).zeroPad(2);
        var date = this['get'+UTC+'Date']().zeroPad(2);
        var hour = this['get'+UTC+'Hours']().zeroPad(2);
        var minute = this['get'+UTC+'Minutes']().zeroPad(2);
        var sec = this['get'+UTC+'Seconds']().zeroPad(2);
        if (this['get'+UTC+'Milliseconds']())
    ...