最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS how to handle a Bootstrap datepicker date to send it out for a REST backend - Stack Overflow

programmeradmin5浏览0评论

I have a 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 which originally returns the date in milliseconds (java.util.Date). The date I receive from the above datepicker element is in the following format

2013-10-01T06:00:00.000Z

How can I convert it to milliseconds so that I can properly ship it to the backend?

I have a 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 which originally returns the date in milliseconds (java.util.Date). The date I receive from the above datepicker element is in the following format

2013-10-01T06:00:00.000Z

How can I convert it to milliseconds so that I can properly ship it to the backend?

Share Improve this question edited Feb 21, 2014 at 1:36 madth3 7,34412 gold badges52 silver badges74 bronze badges asked Oct 27, 2013 at 7:59 user6123723user6123723 11.2k19 gold badges72 silver badges111 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

As I know you can create 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 HTML wrapper for date-picker should be like:

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

So after date change var1 gets milliseconds (see Demo)

Hope this direction will help

You can call Date.parse function on the string:

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论