简体   繁体   中英

Convert UTC date format into javascript format

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

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.

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

The d3.js library has some very solid routines for date conversions. See https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-parse .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM