Nodejs Date Format fromISO(s)

Here you can find the source of fromISO(s)

Method Source Code

/* formatted ISO 8601 timestrings-

2010-06-21T10:41:37.132-04:00//from  w  w  w  .  ja  v  a  2  s . c  o m
2010-06-21T14:41:37Z
2010-06-21
*/
Date.prototype.fromISO= function(s){
   var day, tz, rx=  /^(\d{4}\-\d\d\-\d\d([tT][\d:\.]*)?)([zZ]|([+\-])(\d\d):(\d\d))?$/, p= rx.exec(s) || [];
   if(p[1]){
      day= p[1].split(/\D/).map(function(itm){
         return parseInt(itm, 10) || 0;
      });
      day[1]-= 1;
      day= new Date(Date.UTC.apply(Date, day));
      if(!day.getDate()) return NaN;
      if(p[5]){
         tz= parseInt(p[5], 10)*60;
         if(p[6]) tz += parseInt(p[6], 10);
         if(p[4]== "+") tz*= -1;
         if(tz) day.setUTCMinutes(day.getUTCMinutes()+ tz);
      }
      return day;
   }
   return NaN;
}
if(![].map){
   Array.prototype.map= function(fun, scope){
      var L= this.length, A= Array(this.length), i= 0, val;
      if(typeof fun== 'function'){
         while(i< L){
            if(i in this){
               A[i]= fun.call(scope, this[i], i, this);
            }
            ++i;
         }
         return A;
      }
   }
}

Related

  1. formateDate()
    Date.prototype.formateDate = function() {
      var mm = this.getMonth() + 1;
      var dd = this.getDate();
      return [this.getFullYear(), !mm[1] && '0', mm, !dd[1] && '0', dd].join('');
    };
    
  2. formatf(format)
    Date.prototype.format = function f(format) {
        const o = {
            'M+': this.getMonth() + 1,
            'd+': this.getDate(),
            'h+': this.getHours(),
            'm+': this.getMinutes(),
            's+': this.getSeconds(),
            'q+': Math.floor((this.getMonth() + 3) / 3),
            S: this.getMilliseconds(),
    ...
    
  3. formattedDate()
    Date.prototype.formattedDate = function(){
      var dd   = (this.getDate() < 10 ? "0" : "") + this.getDate();
      var mm   = (this.getMonth() + 1 < 10 ? "0" : "") + (this.getMonth() + 1);
      var yyyy = this.getFullYear();
      return yyyy + '/' + mm + '/' + dd;
    
  4. formattedDate(delemeter)
    Date.prototype.formattedDate = function (delemeter) {
      var dm = delemeter;
      if (!dm) dm = '';
      var yyyy = this.getFullYear().toString();
      var mm = (this.getMonth() + 1).toString();
      var dd = this.getDate().toString();
      if (mm < 10) mm = "0" + mm;
      if (dd < 10) dd = "0" + dd;
      return "" + yyyy + dm + mm + dm + dd;
    ...
    
  5. formattedTime()
    Date.prototype.formattedTime = function(){
      var hours   = (this.getHours() < 10 ? "0" : "")   + this.getHours();
      var minutes = (this.getMinutes() < 10 ? "0" : "") + this.getMinutes();
      var seconds = (this.getSeconds() < 10 ? "0" : "") + this.getSeconds();
      return hours + ':' + minutes + ':' + seconds
    
  6. pattern(fmt)
    Date.prototype.pattern=function(fmt) {      
        var o = {      
        "M+" : this.getMonth()+1, 
        "d+" : this.getDate(), 
        "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, 
        "H+" : this.getHours(), 
        "m+" : this.getMinutes(), 
        "s+" : this.getSeconds(), 
        "q+" : Math.floor((this.getMonth()+3)/3), 
    ...
    
  7. pattern(fmt)
    Date.prototype.pattern=function(fmt) {
        var o = {
            "M+" : this.getMonth()+1, 
            "d+" : this.getDate(), 
            "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, 
            "H+" : this.getHours(), 
            "m+" : this.getMinutes(), 
            "s+" : this.getSeconds(), 
            "q+" : Math.floor((this.getMonth()+3)/3), 
    ...
    
  8. pattern(fmt)
    Date.prototype.pattern = function (fmt) {
        var set = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours() % 12 == 0 ? 12 : this.getHours() % 12,
            "H+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
    ...
    
  9. pattern(fmt)
    Date.prototype.pattern=function(fmt) {        
        var o = {        
        "M+" : this.getMonth()+1, 
        "d+" : this.getDate(), 
        "h+" : this.getHours()%12 == 0 ? 12 : this.getHours()%12, 
        "H+" : this.getHours(), 
        "m+" : this.getMinutes(), 
        "s+" : this.getSeconds(), 
        "q+" : Math.floor((this.getMonth()+3)/3), 
    ...