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

Javascript: parse date to certain string

本文关键字:字符串 日期 Javascript      更新时间:2023-09-26

我希望你能帮我一些JavaScript,因为我有点迷路了。。

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

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

提前感谢!

使用下面链接中的format函数,您可以执行以下操作:

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

JavaScript日期格式

简单的方法: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中获取所有内容。