This question already has answers here:
How to format a JavaScript date
                                
                                    (56个答案)
                                
                        
                                3年前关闭。
            
                    
考虑:

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”?

最佳答案

您可以使用

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

09-16 09:18