Reputation: 1032
How can I convert a date from:
Thu, 1 July 2011 22:30:00
to '2011-07-01T13:51:50.417'
using javascript.
I get the UTC format when I do a new date.
IE causes me issues when I first create a date object as it shows: NaN
Upvotes: 0
Views: 2508
Reputation:
The d3.js library has some very solid routines for date conversions. See https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-parse.
Upvotes: 0
Reputation: 66
You could generate a new Date-Object and then get the different parts:
var today = new Date();
var year = today.getFullYear(); // Returns 2012
var month = today.getMonth()+1; // Returns the month (zero-based)
...
Then you can create a new string like you need it.
Upvotes: 1
Reputation: 9581
possible duplicate try search next time
stackoverflow question
Try http://www.datejs.com/. It is a JavaScript Date Library with an extended Date.parse method and a Date.parseExact method, which lets you specify a format string. See DateJS APIDocumentation.
and then you can manipulate it as you want
Upvotes: 0