Nodejs Utililty Methods Date From

List of utility methods to do Date From

Description

The list of methods to do Date From are organized into topic(s).

Method

fromJSON(json)
Date.fromJSON = function(json) {                                         
  try{        
    if (json.length == 10){
      parts = /^(\d{4})-(\d{2})-(\d{2})$/.exec(json);
      return new Date(Date.UTC(parts[1],parts[2]-1,parts[3],0,0,0));
    }else{
      parts = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).*Z$/.exec(json);
      return new Date(Date.UTC(parts[1],parts[2]-1,parts[3],parts[4],parts[5],parts[6]));
  catch(e){
    return null;    
};
fromOADate()
Number.prototype.fromOADate = function ()
  var jO = new Date(((this - 25569) * 86400000));
  var tz = jO.getTimezoneOffset();
  return new Date(((this - 25569 + (tz / (60 * 24))) * 86400000));
};
fromYYYYMMDD(tmp)
Date.fromYYYYMMDD = function(tmp) {
    return new Date( parseInt(tmp.substr(0, 4).replace(/^0+/, ""))
                                  , parseInt(tmp.substr(4, 2).replace(/^0+/, ""))-1
                                  , parseInt(tmp.substr(6, 2).replace(/^0+/, ""))
                                  );