Nodejs Time Calculate timeToJSON()

Here you can find the source of timeToJSON()

Method Source Code

Date.prototype.timeToJSON = function() {
   return this.toLocaleTimeString().substring(0,5);
};

Related

  1. 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';
    ...
    
  2. timeFmt(aDate)
    var timeFmt = function (aDate) {
        if (null == aDate) {
            return "";
        else {
            return new Date(aDate).format("yyyy-MM-dd hh:mm:ss");
    };
    
  3. timeSecond()
    Date.prototype.timeSecond = function () {
         return ((this.getSeconds() < 10)?"0":"") + this.getSeconds();
    
  4. timeSince(date)
    String.prototype.startsWith = function (str){
      return this.indexOf(str) === 0;
    };
    timeSince = function (date) {
      var seconds = Math.floor((new Date() - date) / 1000);
      var interval = Math.floor(seconds / 31536000);
      if (interval >= 1) {
          if(interval == 1){
            return "about " + interval + " year ago";
    ...
    
  5. timeStr()
    var DAY_WIDTH = 100;
    var DAY_HEIGHT = 80;
    var SIDE_DELTA = 2;
    var DAY_HEADING = ["SUN",
                       "MON",
                       "TUE",
                       "WED",
                       "THU",
                       "FRI",
    ...
    
  6. timeToMidnight()
    Date.prototype.timeToMidnight = function() {
        this.setHours(0);
        this.setMinutes(0);
        this.setMilliseconds(0);
    };
    
  7. time_ago_in_words(date)
    function time_between_in_words(from_date, to_date)
      return format_milliseconds(Math.abs(from_date.getTime()-to_date.getTime()));
    function time_ago_in_words(date)
      return format_milliseconds(Math.abs(Date.now()-date.getTime()));
    function format_milliseconds(milsecs)
    ...
    
  8. time_since()
    var chunks = [
      [60 * 60 * 24 * 365, 'year'],
      [60 * 60 * 24 * 30, 'month'],
      [60 * 60 * 24 * 7, 'week'],
      [60 * 60 * 24, 'day'],
      [60 * 60, 'hour'],
      [60, 'minute']
    ];
    Date.prototype.time_since = function() {
    ...
    
  9. timesince(now)
    Date.prototype.timesince = function(now) {
      var chunks = [
        [ 60 * 60 * 24 * 365, 'year', 'years'],
        [ 60 * 60 * 24 * 30, 'month', 'months' ],
        [ 60 * 60 * 24, 'day', 'days' ],
        [ 60 * 60, 'hour', 'hours' ],
        [ 60, 'minute', 'minutes' ]
      ];
      now = now || new Date();
    ...