1

I am using this dateTimePicker for my angularjs app, and the issue I am having is that what the user enters as time gets translated to a different, UTC based time which differs many hours (screen shot below, the component and the text next to it are both using the same ng-model).

enter image description here

Is there anyway to force this component to produce the output exactly as user enters? like in this case, I would like to get "2016-05-24 12:00 AM" out of it!

Bimal Das
  • 1,882
  • 5
  • 28
  • 53
Behrooz
  • 1,895
  • 4
  • 31
  • 47

2 Answers2

1

Use the date filter and leave the timezone empty on your date value, leaving the timezone empty will use browser default timezone:

{{date | date: 'yyyy-MM-dd hh:mm:ss Z' : ''}}

reference: https://docs.angularjs.org/api/ng/filter/date

Shadi Shaaban
  • 1,670
  • 1
  • 10
  • 17
1

You can use this Code :

var d = new Date($scope.date);
var day = d.getDate();
var mon = d.getMonth()+1;
var year = d.getFullYear();
var hour = d.getHours();
var min = d.getMinutes();

if(day <10) day = "0"+day;
if(mon <10) mon = "0"+mon;

$scope.newDate = day+"-"+mon+"-"+year+" "+ hour + ":"+ min;
alert($scope.newDate);

To convert this 24 hour to 12 hour clock , follow these two question's answers .

Converting 24 hour time to 12 hour time w/ AM & PM using Javascript

Javascript: convert 24-hour time-of-day string to 12-hour time with AM/PM and no timezone

Community
  • 1
  • 1
Bimal Das
  • 1,882
  • 5
  • 28
  • 53