0

hi i am using angularjs datepicker functionality using npm i angularjs-datepicker working fine but i need to show time like(15-12-2017 05:14 PM) help how to format the datepicker here i mentioned reference link also i tired from controller it's came but when i click date picker date shown wrongly .there is any specify format is there help or how to solve that problem

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>

Controller

  $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;
            }
jose
  • 1,044
  • 1
  • 12
  • 35

2 Answers2

0

According to the DOCs you have to use the AngularJs date format

Option: date-format=""

Type: String

Default: String(new Date())

Description: Set the date format you want to use, see the list here

<datepicker date-format="dd-MM-yyyy hh:mm a" selector="form-control">
   <input type="text" ng-model="QuoteDate"/>
</datepicker>
Keyur Shah
  • 536
  • 6
  • 20
0

It's Working for me. Try this. Hope it will help you.

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'
    });
Nikita
  • 437
  • 2
  • 12
  • when select date time appears crct but not able change date once i select in date picker kindly check once – jose Dec 16 '17 at 06:16
  • @jose please check I have edited answer, hope it will help you. – Nikita Dec 18 '17 at 05:30
  • same problem once u use that datepicker above mentioned link and try then only u understand my pblm:) @Nikita – jose Dec 18 '17 at 07:34