-1

i want get format data like this 201507280945 not like this Thu May 29 2014 13:50:00 GMT-0400 (Eastern Standard Time)

i put this code

var time = new Date();

i get this Thu May 29 2014 13:50:00 GMT-0400 (Eastern Standard Time)

Manashvi Birla
  • 2,811
  • 3
  • 12
  • 27
  • possible duplicate of [How to format a JavaScript date](http://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – Dmitry Grigoryev Jul 28 '15 at 12:22

2 Answers2

1

Get the values individually and do concat.

            var Current = new Date();
            var DD = Current.getDate();
            var MM = Current.getMonth() + 1; //January is 0
            var YYYY = Current.getFullYear();
            var hr = Current.getHours();
            var min = Current.getMinutes();
            var milsec = Current.getMilliseconds();
            and so on.............
Vivek Ranjan
  • 1,360
  • 2
  • 11
  • 31
0

How about write your own date formatter.

    function dateFormat(date) {
      var hours = date.getHours();
      var minutes = date.getMinutes();
      var ampm = hours >= 12 ? 'pm' : 'am';
      hours = hours % 12;
      hours = hours ? hours : 12; // the hour '0' should be '12'
      minutes = minutes < 10 ? '0'+minutes : minutes;
      var strTime = hours + ':' + minutes + ' ' + ampm;
//below is to format to whatever you want, for example month/day/year time...
      return date.getMonth()+1 + "/" + date.getDate() + "/" + date.getFullYear() + "  " + strTime;
    }

    var dateString = formatDate(new Date());

    console.log(dateString );
Hammer
  • 7,509
  • 9
  • 39
  • 68
  • 1
    user hasn't asked the result in format mm/dd/yyyy 000. Please read the question again. – Vivek Ranjan Jul 28 '15 at 12:09
  • @ Vivek Ranjan, well, giving some rooms to practice gives better understanding? Note my comment that "//below is to format to whatever you want, for example month/day/year time..." – Hammer Jul 29 '15 at 06:03