0

How can I change the output to be more readable? from this 2015-04-25T00:00:00Z to 2015-04-2 00:00:00-00:00:00

I am using this (new Date()).toISOString()

Flap Jack
  • 97
  • 1
  • 14
  • Which Javascript reference are you using? Looks more like a string operation to me than data formatting. – hakre May 14 '15 at 08:05

2 Answers2

1

Dates are very strange beast in javascript. If at all possible I would highly recommend using a date library like momentjs to handle this for you. Using moment this would be as simple as:

var formattedDate = moment().format('YYYY-MM-DD hh:mm:ss')

dmamills
  • 197
  • 1
  • 5
0

This is one way to handle it in JavaScript. You get the Date and then the various parts. Then you concatenate them together into a variable to use as you wish.

var d = new Date();
var dy = d.getDate();
var dmth = d.getMonth();
var dyr = d.getFullYear();
var dFullDate = dyr+ '/' +dmth+ '/' +dy;
andre mcgruder
  • 1,120
  • 1
  • 9
  • 12