中国标准时间改为formatTime格式

1、toLocaleDateString (根据本地时间把Date 对象的日期部分转换为字符串):

var time = new Date();
var formatTime = time.toLocaleDateString();

//print
2017/4/18

2、将时间指定为 年-月-日 格式,例:2017-1-1

var date = new Date('Thu May 12 2016 08:00:00 GMT+0800 (中国标准时间)');  

formatTime=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();

//print formatTime
2016-9-20

这里要注意月份的获取,表示月份的参数介于 0 到 11 之间,所以如果想获得当前真实月份,还需 +1。

原文地址:https://www.cnblogs.com/yourstars/p/6523061.html