Nodejs String Format toFormattedString(include_time)

Here you can find the source of toFormattedString(include_time)

Method Source Code

Date.prototype.toFormattedString = function(include_time){
  str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
  if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
  return str;/*from  w  w w  .  j a  va  2 s. c  o  m*/
}

Date.parseFormattedString = function (string) {
  var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
  var d = string.match(new RegExp(regexp, "i"));
  if (d==null) return Date.parse(string); // at least give JavaScript a crack at it.
  var offset = 0;
  var date = new Date(d[5], 0, 1);
  if (d[3]) { date.setMonth(d[3] - 1); }
  if (d[5]) { date.setDate(d[1]); }
  if (d[7]) {
    date.setHours(parseInt(d[7], 10));    
  }
  if (d[8]) { date.setMinutes(d[8]); }
  if (d[10]) { date.setSeconds(d[10]); }
  return date;
}

Related

  1. toFormattedString(format)
    WScript.echo("Date Extensions Module Loaded");
    Date.prototype.toFormattedString = function (format) {
        var year = (this.getFullYear()).toString();
        var month = (1 + this.getMonth()).toString();
        var day = (this.getDate()).toString();
        month = month.length > 1 ? month : "0" + month;
        day = day.length > 1 ? day : "0" + day;
        switch (format) {
            case "YYYYMMDD": return year + month + day; break;
    ...
    
  2. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time) {
      var str = this.getFullYear() + '-' + Date.padded2(this.getMonth() + 1) + '-' + Date.padded2(this.getDate());
      return str;
    
  3. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time)
       str = this.getFullYear() + "." + Date.padded2(this.getMonth()+1) + "." + Date.padded2(this.getDate());
       if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
       return str;
    
  4. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time)
       str = Date.padded2(this.getDate()) + " " + Date.months[this.getMonth()] + " " + this.getFullYear();
       if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
       return str;
    
  5. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time)
      var str = Date.padded2(this.getDate()) + "/" + Date.padded2(this.getMonth() + 1) + "/" + this.getFullYear();
      return str;
    
  6. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time){
      str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
      if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
      return str;
    Date.parseFormattedString = function (string) {
      var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
      var d = string.match(new RegExp(regexp, "i"));
      if (d==null) return Date.parse(string); 
    ...
    
  7. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time){
      str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
      if (include_time) { str += " ? + this.getHours() + ":" + this.getPaddedMinutes() }
      return str;
    Date.parseFormattedString = function (string) {
      var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ??([0-9]{1,2}):([0-9]{2})? *)?)?)?';
      var d = string.match(new RegExp(regexp, "i"));
      if (d==null) return Date.parse(string); 
    ...
    
  8. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time){
      str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
      if (include_time) { hour=this.getHours(); str += " " + this.getAMPMHour() + ":" + this.getPaddedMinutes() }
      return str;
    Date.parseFormattedString = function (string) {
      var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
      var d = string.match(new RegExp(regexp, "i"));
      if (d==null) return Date.parse(string); 
    ...
    
  9. toFormattedString(include_time)
    Date.prototype.toFormattedString = function(include_time){
      str = this.getDate() + "/" + (this.getMonth() + 1) + "/" + this.getFullYear();
      if (include_time) { str += " " + this.getHours() + ":" + this.getPaddedMinutes() }
      return str;
    Date.parseFormattedString = function (string) {
      var regexp = '([0-9]{1,2})/(([0-9]{1,2})/(([0-9]{4})( ([0-9]{1,2}):([0-9]{2})? *)?)?)?';
      var d = string.match(new RegExp(regexp, "i"));
      if (d==null) return Date.parse(string.replace(/\
    ...