Ahmer Khan
Ahmer Khan

Reputation: 767

Display date in localized format in AngularJS

I have a scenario in which I have to set a date for event, the date picker should take the date format in localized format according to country or region. How can I do that in AngularJS? I have tried many solutions but didn't find any appropriate one.

Upvotes: 1

Views: 150

Answers (1)

Nisal Edu
Nisal Edu

Reputation: 7591

You can use toLocaleDateString()

Reference

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString

var today = new Date();

var date = new Date(Date.UTC(2012, 11, 20, 3, 0, 0));

 console.log(date.toLocaleDateString('en-US'));
 console.log(today.toLocaleDateString('en-US'));

Upvotes: 0

Related Questions