简体   繁体   English

将UTC日期格式转换为javascript格式

[英]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. Thu, 1 July 2011 22:30:00'2011-07-01T13:51:50.417'使用JavaScript。

I get the UTC format when I do a new date. 当我重新约会时,我得到的是UTC格式。

IE causes me issues when I first create a date object as it shows: NaN 当我第一次创建日期对象时,IE导致我出现问题,如下所示: NaN

You could generate a new Date-Object and then get the different parts: 您可以生成一个新的Date-Object,然后得到不同的部分:

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 下次可能重复尝试搜索stackoverflow问题
Try http://www.datejs.com/ . 尝试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. 它是一个JavaScript日期库,具有扩展的Date.parse方法和Date.parseExact方法,可用于指定格式字符串。 See DateJS APIDocumentation. 请参阅DateJS APIDocumentation。

and then you can manipulate it as you want 然后您可以根据需要对其进行操作

The d3.js library has some very solid routines for date conversions. d3.js库具有一些非常可靠的用于日期转换的例程。 See https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-parse . 参见https://github.com/mbostock/d3/wiki/Time-Formatting#wiki-parse

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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