简体   繁体   中英

How to convert Date format in Javascript

I want to change date format sequence from yy-mm-dd to dd-mm-yy

How can I do it in Javascript ?

I have tried

var now = new Date();

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

But its not working for me

Here is a clear and simple approach

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
var dateFormatted = (now.getMonth()+1)+"-"+now.getDate()+"-"+now.getFullYear();

您可以使用下面提到的函数来格式化日期

utilities.FormatDate(new Date(),"GMT", "dd/MM/yyyy")
function dateformat(date)
{
  var yourdate = new Date(date);
 yourdate = yourdate.getDate() + '-' + yourdate.getMonth() +1 + "-"  +yourdate.getFullYear();
}

use - or / as you like

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