格式化字符串日期" 2015年6月1日星期一00:00:00 GMT + 0100(IST)"到" YYYY-MM-DD"

时间:2015-06-18 09:29:04

标签: javascript angularjs date format

如何转换字符串" Mon Jun 01 2015 00:00:00 GMT + 0100(IST)"进入2015-03-25,Angular和javascript的新手。是否有任何功能可以进行此转换?

3 个答案:

答案 0 :(得分:2)

好的,这对我有用

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);

答案 1 :(得分:0)

您可以尝试这样:

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

答案 2 :(得分:0)

答案:

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