Javascript 当前时间

Javascript 当前时间,javascript,angularjs,Javascript,Angularjs,我使用以下代码获取angularJS中的当前时间: $scope.getDatetime = function() { return (new Date()) + "abc.txt" ; }; 当前时间的正确代码是多少,单位为YYYY-MM-DD时分秒?可能您需要此代码 $scope.getDatetime = function() { var date = new Date(); var day = date.getDat

我使用以下代码获取angularJS中的当前时间:

    $scope.getDatetime = function() {
        return (new Date()) + "abc.txt" ;
    };
当前时间的正确代码是多少,单位为
YYYY-MM-DD时分秒

可能您需要此代码

  $scope.getDatetime = function() {
        var date = new Date();
        var day =  date.getDate();
        var month = ((date.getMonth() + 1) > 9) ? date.getMonth() + 1 :  "0" + (date.getMonth() + 1)
        var year = date.getFullYear();
        var hours = date.getHours();
        var minutes = date.getMinutes();
        var seconds =  date.getSeconds();
        return year+"/"+month+"/"+day+" "+hours+":"+minutes+":"+seconds;
    };
var s=new Date().toISOString();
控制台日志;
s=s.切片(0,19);
s=s.replace('T','-');
s=s.replace(“:”,“-”);
s=s.replace(“:”,“-”);

控制台日志不需要小时数?还添加了
hours
。谢谢你指出