0

嗨,我正在使用 angularjs datepicker 功能,使用npm i angularjs-datepicker工作正常,但我需要显示时间,如(15-12-2017 05:14 PM)帮助如何格式化 datepicker 在这里我提到了参考链接,我也厌倦了控制器它来了但是当我点击日期选择器日期显示错误。有任何指定格式是否有帮助或如何解决该问题

https://www.npmjs.com/package/angularjs-datepicker

html

<div class="hackyhack" datepicker datepicker-class="test-custom-class" 
   date-format="dd-MM-y" >
 <input type="text" id="AddQuoteDate" name="QuoteDate" size="4"
 ng-model="QuoteDate" placeholder="Enter Quote Date"
 ng-change="QuoteDatechange(QuoteDate)"
 class="form-control angular-datepicker-input"
 required title="Enter Quote Date"/>
  </div>

控制器

  $scope.QuoteDatechange = function (Quotedate) {
 var date = new Date();
            var hours = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
            var am_pm = date.getHours() >= 12 ? "PM" : "AM";
            hours = hours < 10 ? "0" + hours : hours;
            var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
            var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
              time = hours + ":" + minutes + ":" + seconds + " " + am_pm;
            $scope.QuoteDate = Quotedate + " " + time;
            }
4

2 回答 2

0

它为我工作。尝试这个。希望它会帮助你。

var currentdate = new Date();
var hours = currentdate.getHours();
var minutes = currentdate.getMinutes();
var ampm = hours >= 12 ? 'pm' : 'am';
hours = hours % 12;
hours = hours ? hours : 12; // the hour '0' should be '12'
minutes = minutes < 10 ? '0'+minutes : minutes;
var strTime = hours + ':' + minutes + ampm;
$scope.QuoteDate = pad(currentdate.getDate()) + "/"
                + pad(currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "
                + strTime;

function pad(s) { return (s < 10) ? '0' + s : s; }


<input type="text" id="AddQuoteDate" name="QuoteDate" size="4" ng-model="QuoteDate" placeholder="Enter Quote Date" class="form-control angular-datepicker-input" required title="Enter Quote Date"/>

   $('#AddQuoteDate').datetimepicker({
        minDate:new Date(),
        format: 'DD/MM/YYYY hh:mma'
    });
于 2017-12-15T13:19:04.943 回答
0

根据文档,您必须使用AngularJs 日期格式

选项:日期格式=“”

类型:字符串

默认值:字符串(新日期())

描述:设置您要使用的日期格式,请参见此处的列表

<datepicker date-format="dd-MM-yyyy hh:mm a" selector="form-control">
   <input type="text" ng-model="QuoteDate"/>
</datepicker>
于 2017-12-15T12:04:47.933 回答