Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:日期为字符串,以毫秒为单位_Javascript_Angularjs_Date - Fatal编程技术网

Javascript AngularJS:日期为字符串,以毫秒为单位

Javascript AngularJS:日期为字符串,以毫秒为单位,javascript,angularjs,date,Javascript,Angularjs,Date,我收到一个格式为“27/02/2018 09:00”的字符串形式的日期如何将其传递到毫秒?提前感谢您可以从@angular/common 模块。这应该是个骗局 我想不出另外一种方法(使用内置的日期过滤器),所以只需使用split和date就可以了: (function() { 'use strict'; // new app angular.module('myApp', []); // new controller angular .module('m

我收到一个格式为“27/02/2018 09:00”的字符串形式的日期如何将其传递到毫秒?提前感谢

您可以从
@angular/common

模块。这应该是个骗局

我想不出另外一种方法(使用内置的日期过滤器),所以只需使用
split
date
就可以了:

(function() {
  'use strict';
    // new app  
  angular.module('myApp', []);

    // new controller
  angular
    .module('myApp')
    .controller('MyController', MyController);

  MyController.$inject = ['$scope'];

  function MyController($scope) {
    var my_date = "27/02/2018 09:00";
    var parts = my_date.split(' ');
    var date_parts = parts[0].split('/');
    var time_parts = parts[1].split(':');
    var date_obj = new Date(date_parts[2], date_parts[1], date_parts[0], time_parts[0], time_parts[1]);
    $scope.milliseconds = date_obj.getTime();
  }

})();

演示:

您想在控制器/服务或视图中执行此操作吗?在控制器中