Prasad Kanaparthi
Prasad Kanaparthi

Reputation: 6563

input type="date" giving previous day date in HTML5

I'm using below code for date.

<input type="date" value="{{data.endDate | date: "MM/dd/yyyy"}}" ng-model="data.endDate" />

If i select today date (11/22/2015) in the controller the endDate value is 2015-11-21T18:30:00.000Z.

  1. How can i get exact selected date value?
  2. The model date is not displaying.

Upvotes: 1

Views: 2246

Answers (2)

Sukumar Kumarasamy
Sukumar Kumarasamy

Reputation: 1

Thanks nishi bangar,

The simplest way, ones the date has been selected from the date picker, "convert the date object to a string using Date's locale convention method, dateObject.toLocaleDateString(). Refer this for further understanding.

Upvotes: -1

Nishi Bangar
Nishi Bangar

Reputation: 948

This happens because, the date object for the selected date is created and is represented according to UTC standards.

Solution

  1. You will have to do a bit of temporal calculations in order to get the expected date value. Refer this article to understand the actual working to reach the desired goal.

  2. The simplest way, ones the date has been selected from the date picker, "convert the date object to a string using Date's locale convention method, dateObject.toLocaleDateString(). Refer this for further understanding.

example : $scope.dateOfTransactionFilter.toLocaleDateString()

Hope this helps. Cheers

Upvotes: 1

Related Questions