Javascript:将日期解析为某个字符串

时间:2012-03-03 20:08:50

标签: javascript date

我希望你能用一些JavaScript来帮助我,因为我有点迷失了......

我正在尝试以最简单的方式实现Date对象的下一格式字符串。

var now = new Date();
//how to convert to a pattern like this example: "30/1/2012 20:00:00"  ?

提前致谢!

2 个答案:

答案 0 :(得分:1)

使用以下链接中的format功能,您可以执行以下操作:

var now = new Date();
now.format("dd/mm/yyyy hh:mm:ss");

JavaScript Date Format

答案 1 :(得分:1)

简单方法: http://jsfiddle.net/tftd/UtVnU/

var date = new Date();
//how to convert to a pattern like this example: "30/1/2012 20:00:00"  ?
var time = date.getDay()+"/"+date.getMonth()+"/"+date.getYear()+" "+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();

alert(time) /* Outputs 6/2/112 22:16:15 */

您可以从变量date获取所有内容。