Nodejs Time Calculate getPrettyDateTime()

Here you can find the source of getPrettyDateTime()

Method Source Code

/**/*from ww  w.  j  a  v a  2 s .  co m*/
 * Provides a "pretty" datetime format to the Date object.
 *
 * Like: 12/04/2011 7:12 PM
 */
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();
};

Related

  1. 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();
    };
    
  2. getDigitalTime()
    Date.prototype.getDigitalTime = function(){  
      if  (this.getHours() > 12){
        var hour = this.getHours() - 12;
        var ampm = "PM";
      }else{
        var hour = this.getHours();
        var ampm = "AM";
      if (this.getMinutes() < 10)
    ...
    
  3. 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;
    ...
    
  4. getFullDateTime()
    Date.prototype.getFullDateTime = function() {
        return this.getFullYear()+'-'+this.getMonthFormatted()+'-'+this.getDayFormatted()+' '+this.getHoursFormatted()+':'+this.getMinutesFormatted()+':'+this.getSecondsFormatted();
    
  5. 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;
    
  6. getPrettyTime()
    Date.prototype.getPrettyTime = function () {
      var minutes = (this.getMinutes() < 10) ? "0" + this.getMinutes() : this.getMinutes();
      var hours = this.getHours();
      var ampm = "AM";
      if (hours > 12) {
        ampm = "PM";
        hours -= 12;
      } else if (hours == 12) {
        ampm = "PM";
    ...
    
  7. getTimeAmPm()
    Date.prototype.getTimeAmPm = function () {
      let hours = this.getHours();
      let minutes = this.getMinutes();
      let ampm = hours >= 12 ? 'pm' : 'am';
      hours = hours % 12;
      hours = hours ? hours : 12; 
      minutes = minutes < 10 ? '0' + minutes : minutes;
      let strTime = hours + ':' + minutes + '' + ampm;
      return strTime;
    ...
    
  8. getTimeShift()
    Date.prototype.getTimeShift = function() {
        return this.getTimezoneOffset() < this.stdTimezoneOffset()?3:2;
    };
    
  9. getUnixTime()
    getQueryString = function (field, url) {
        var href = url || window.location.href;
        var reg = new RegExp('[?&]' + field + '=([^&#]*)', 'i');
        var string = reg.exec(href);
        return string ? string[1] : null;
    };
    Date.prototype.getUnixTime = function () {
        return this.getTime() / 1000 | 0
    };
    ...