如何以“2017-03-03 09:46:22.103”等正常格式转换日期?

时间:2017-03-04 04:47:26

标签: javascript date datetime

考虑:

var myDate = $scope.today;
var previousDay = new Date(myDate);
previousDay.setDate(myDate.getDate() - 1);
var date = previousDay; // 2017-03-04 09:46:22.103 +5.30 GMT

我如何才能获得“2017-03-03 09:46:22.103”?

2 个答案:

答案 0 :(得分:1)

您可以使用

var requiredDateFormat = previousDay.toLocaleDateString() + " " + previousDay.toLocaleTimeString();

答案 1 :(得分:0)

您可以使用new Date().toJSON();。它将返回"2017-03-04T04:55:50.786Z"