AngularJS how to handle datepicker Bootstrap date to send it for REST backend

I have angular -strap bootstrap datepicker

<input id="dp5" class="span8" type="text" ng-model="obj.date" data-date-format="mm/dd/yyyy"  placeholder="Pick a Date" bs-datepicker>

The backend is a Spring MVC REST application that initially returns the date in milliseconds (java.util.Date). The date I get from the specified datepicker is in the following format

2013-10-01T06:00:00.000Z

How can I convert it to milliseconds so that I can send it to the server correctly?

+4
source share
2 answers

As I know, you can create a directive to handle it:

Demo Plunker

app.directive('datetimez', function() {
    return {
        restrict: 'A',
        require : 'ngModel',
        link: function(scope, element, attrs, ngModelCtrl) {
          element.datetimepicker({
            dateFormat:'dd/MM/yyyy hh:mm:ss',
            language: 'pt-BR'
          }).on('changeDate', function(e) {

            var outputDate = new Date(e.date);

           var n = outputDate.getTime();


           ngModelCtrl.$setViewValue(n);
            scope.$apply();
          });
        }
    };
});

And the HTML wrapper for selecting the date should look like this:

  <div id="date" class="input-append" datetimez ng-model="var1">

, var1 (. )

,

+4

Date.parse :

Date.parse("2013-10-01T06:00:00.000Z") // 1380607200000
+4

All Articles