Nodejs Time Calculate getDigitalTime()

Here you can find the source of getDigitalTime()

Method Source Code

//to get time in a digital format
Date.prototype.getDigitalTime = function(){   
   // flaw for midnight
   if   (this.getHours() > 12){
      var hour = this.getHours() - 12;
      var ampm = "PM";
   }else{//from   w  w  w.  java  2  s .  com
      var hour = this.getHours();
      var ampm = "AM";
   }
   
   if (this.getMinutes() < 10)
      var min = "0" + this.getMinutes();
   else{var min = this.getMinutes();}
   return hour+":"+min+" "+ampm;
}

//to get a digital clock
Date.prototype.getDigitalClock = function(){
   return "Current Time: "+this.getDigitalTime()+"&nbsp;&nbsp;"+this.getNumberDate()+" "+this.getDayOfWeek(this.getDay());
}

//get a timestamp in numberTime + numberDate format
function timeStamp(){
   var time = new Date();
   return time.getNumberTime() + " " + time.getNumberDate();
}

// get current time in seconds
function curTime(){
   var time = new Date();   
   return (time.getTime()/1000);
}

//converts seconds into h:m:s format
function converter(){

}//end converter()

Related

  1. dateTime()
    Date.prototype.dateTime = function() {
       var yyyy = this.getFullYear().toString();
       var mm = (this.getMonth()+1).toString(); 
       var dd  = this.getDate().toString();
       var hh = this.getHours().toString();
       var min = this.getMinutes().toString();
       var sec = this.getSeconds().toString();
       var time = (hh[1]?hh:"0"+hh[0]) + ":" + (min[1]?min:"0"+min[0]) + ":" + (sec[1]?sec:"0"+sec[0]);
       var date = (dd[1]?dd:"0"+dd[0]) + "/" + (mm[1]?mm:"0"+mm[0]) + "/" + yyyy;
    ...
    
  2. datetime()
    Date.prototype.datetime = function() {
      var y = this.getFullYear();
      var M = this.getMonth() + 1;
      var d = this.getDate();
      var h = this.getHours();
      var m = this.getMinutes();
      var s = this.getSeconds();
      M = M < 10 ? '0' + M : M;
      d = d < 10 ? '0' + d : d;
    ...
    
  3. distance_of_time_in_words(to)
    Date.prototype.distance_of_time_in_words = function(to) {
      distance_in_milliseconds = to - this;
      distance_in_minutes = Math.round(Math.abs(distance_in_milliseconds / 60000));
      if (distance_in_minutes == 0) {
        words = "less than a minute";
      } else if (distance_in_minutes == 1) {
        words = "1 minute";
      } else if (distance_in_minutes < 45) {
        words = distance_in_minutes + " minutes";
    ...
    
  4. fromUnixTime(value)
    Date.fromUnixTime = function(value) {
        return new Date(value * 1000);
    };
    
  5. getDateTimeStr()
    Date.prototype.getDateTimeStr = function () {
      let month = this.getMonth() + 1;
      if (month < 10) month = '0' + month;
      let day = this.getDate();
      if (day < 10) day = '0' + day;
      return this.getFullYear() + '-' + month + '-' + day + ' ' + this.getTimeAmPm();
    };
    
  6. getFormatTime()
    Date.prototype.getFormatTime = function (){
      var date = '';
      date += this.getFullYear() < 10 ? '0' + this.getFullYear() +'-' : this.getFullYear() +'-' ;
      date += this.getMonth() + 1 < 10 ? '0' + (this.getMonth() + 1) +'-' : (this.getMonth() + 1) + '-';
      date += this.getDate()< 10 ? '0' + (this.getDate()) : this.getDate() + ' ';
      date += this.getHours()< 10 ? '0' + (this.getHours()) +'-' : this.getHours() + ':';
      date += this.getMinutes() < 10 ? '0' + (this.getMinutes()) +'-' : this.getMinutes() + ':';
      date += this.getSeconds() < 10 ? '0' + (this.getSeconds()) : this.getSeconds();
      return date;
    ...
    
  7. getFullDateTime()
    Date.prototype.getFullDateTime = function() {
        return this.getFullYear()+'-'+this.getMonthFormatted()+'-'+this.getDayFormatted()+' '+this.getHoursFormatted()+':'+this.getMinutesFormatted()+':'+this.getSecondsFormatted();
    
  8. getNumberTime()
    Date.prototype.getNumberTime = function() {
      var hour = this.getHours();  
      if (this.getMinutes().length == 1)
        var min = "0" + this.getMinutes();
      else{var min = this.getMinutes();}
      var secs = this.getSeconds();  
      return hour +":"+ min +":"+ secs;
    
  9. getPrettyDateTime()
    Date.prototype.getPrettyDateTime = function () {
      var month = this.getMonth() + 1;
      var day = (this.getDate() < 10) ? "0" + this.getDate() : this.getDate();
      return month + "/" + day + "/" + this.getFullYear() + " " + this.getPrettyTime();
    };