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!

2
  • Could you post a plunker? Commented May 27, 2016 at 18:22
  • How are you displaying the text? If you are using the date filter it would have formatted according to the browser timezone by default. You need to add more code. Commented May 27, 2016 at 18:24

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Worked perfectly, except I had to change that "Z" to an "a"!
Excellent! Yes you could define any suitable format for display.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.