将字符串日期 "Mon Jun 01 2015 00:00:00 GMT+0100 (IST)" 格式化为 "YYYY-MM-DD"

Format string date "Mon Jun 01 2015 00:00:00 GMT+0100 (IST)" to "YYYY-MM-DD"

如何将字符串 "Mon Jun 01 2015 00:00:00 GMT+0100 (IST)" 转换为 2015-03-25,Angular 和 javascript 的新增内容。有什么函数可以转换吗?

你可以这样试试:

var dt = new.Date(myDate);
var year = dt.getUTCFullYear();
var month = dt.getUTCMonth() + 1;
var day = dt.getUTCDate();
var myNewdate= year + "-" + month + "-" + day;

答案:

var longDate = Date.parse('Mon Jun 01 2015 00:00:00 GMT+0100 (IST)');
var date = new Date(longDate);
alert(date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() );

Example

好的,这对我有用

2015 年 6 月 1 日星期一 00:00:00 GMT+0100 (IST)

var date = new Date('Mon Jun 01 2015 00:00:00 GMT+0100 (IST)');
console.log(date);
var formatedDate = (date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate());
console.log('Formated date' + formatedDate);