如何在Javascript中转换日期格式

时间:2013-12-19 13:45:37

标签: javascript

我想将日期格式序列从yy-mm-dd更改为dd-mm-yy

我怎样才能在Javascript中完成?

我试过了

var now = new Date();

now.format("mm-dd-yy");

但它不适合我

4 个答案:

答案 0 :(得分:1)

这是一个简单明了的方法

var now = new Date();     
var dd = now.getDate();    //returns date
var mm = now.getMonth()+ 1; //returns month and you need to add1 because it is array
var yy = now.getFullYear(); //returns full year 
var st = dd + '-' + mm  + "-" + yy;  //format as string

答案 1 :(得分:0)

var dateFormatted = (now.getMonth()+1)+"-"+now.getDate()+"-"+now.getFullYear();

答案 2 :(得分:0)

您可以使用下面提到的功能格式化日期

utilities.FormatDate(new Date(),"GMT", "dd/MM/yyyy")

答案 3 :(得分:0)

function dateformat(date)
{
  var yourdate = new Date(date);
 yourdate = yourdate.getDate() + '-' + yourdate.getMonth() +1 + "-"  +yourdate.getFullYear();
}

使用 - 或/如你所愿