Jay
Jay

Reputation: 1039

Date changing to US Format in Angular during Validation

I am doing some validation in angular where date added by user has to be greater than some other date on form.

On dateChange on input:From, i call this method which check for validation but when i try to get the date entered, it get date in US version.

ex: var from = new Date(viewValue);

viewvalue is "08/04/2016" but from comes out as 'Thu Aug 04 2016 00:00:00 GMT+0100 (GMT Daylight Time)'

What can i do so that from comes out as April 8th ?

Thanks.

Upvotes: 1

Views: 46

Answers (1)

thegio
thegio

Reputation: 1243

I suggest you to use Momentjs:

http://momentjs.com

Momentjs Formats

var from = new Date(viewValue);
var date = moment(from).format('MMM Do');

Fiddle

Upvotes: 2

Related Questions