Nodejs Time Calculate time()

Here you can find the source of time()

Method Source Code

Date.prototype.time = function(){
  var hours = this.getHours();
  if (hours === 0 || hours === 24) hours = 12;
  if (hours > 12) hours -= 12;

  var minutes = this.getMinutes();
  if (minutes < 10) minutes = "0" + minutes;

  var ampm = this.getHours() >= 12 ? "pm" : "am";

  return "" + hours + ":" + minutes + ampm;
}

Related

  1. onlyTime()
    Date.prototype.onlyTime = function () {
      return this.toTimeString().split(" ")[0];
    };
    
  2. p8DeDate(time)
    Date.prototype.p8DeDate = function(time) {
      var d = this;
      function pad(n) {
        return n < 10 ? '0' + n : n;
      function pad3(n) {
        if(n < 10) {
           return '00' + n;
        } else if(n < 100) {
    ...
    
  3. prettyDate(time)
    function prettyDate(time) {
        var date = new Date().setISO8601(time || "");
        console.log('date: ' + date);
        var diff = (((new Date()).getTime() - date.getTime()) / 1000);
        console.log('diff: ' + diff);
        var day_diff = Math.floor(diff / 86400);
        console.log('daydiff: ' + day_diff);
        if (isNaN(day_diff) || day_diff < 0 || day_diff >= 31) {
          console.log('some shit went bad');
    ...
    
  4. setTimeToNow()
    Date.prototype.setTimeToNow = function () 
        var n = Date.relativeTo || new Date();
        this.setHours(n.getHours());
        this.setMinutes(n.getMinutes());
        this.setSeconds(n.getSeconds());
        this.setMilliseconds(n.getMilliseconds());
        return this;
    
  5. time()
    Date.prototype.time = function () {
        return this.getHours().zfill(2) + ":" + this.getMinutes().zfill(2) + ":" + this.getSeconds().zfill(2);
    };
    
  6. time24()
    Date.prototype.time24 = function()
      var hours = "" + this.getHours();
      var minutes = "" + this.getMinutes();
      var seconds = "" + this.getSeconds();
      if(hours.length < 2)
        hours = "0"+hours;
      if(minutes.length < 2)
        minutes = "0"+minutes;
    ...
    
  7. timeAgo(date)
    String.prototype.format = function(obj) {
      var args = arguments;
      var str = this;
      return str.replace(/\{[\w\d_-]+\}/g, function(part) {
        part = part.slice(1, -1);
        var index = parseInt(part, 10);
        if (isNaN(index)) {
          return obj[part];
        } else {
    ...
    
  8. timeAgoInWords(relativeDate)
    "use strict";
    Date.prototype.timeAgoInWords = function (relativeDate) {
        var delta;
        relativeDate = relativeDate || new Date();
        delta = parseInt((relativeDate.getTime() - this) / 1000, 10);
        if (delta < 60) {
            return 'less than a minute ago';
        } else if (delta < 120) {
          return 'about a minute ago';
    ...
    
  9. timeFmt(aDate)
    var timeFmt = function (aDate) {
        if (null == aDate) {
            return "";
        else {
            return new Date(aDate).format("yyyy-MM-dd hh:mm:ss");
    };