Kamaldeep Singh
Kamaldeep Singh

Reputation: 897

How to perform internationalization of custom date using angularjs in HTML

Suppose there is a date say

<script>
    module.controller("mycontroller", function($scope) {

        $scope.theDate  = new Date();

    });
</script>

and in HTML I have written

<div ng-controller="mycontroller">
    {{theDate  | date : "fullDate"}}
</div>

So this returns date in simple English.

What I need is to get date in country based language like fr, ja, etc. Though I am even using Angular Moment to get 'Time from now' but I am unable to get date in custom language.

Upvotes: 0

Views: 257

Answers (1)

Stafford Williams
Stafford Williams

Reputation: 9806

To get the date now, use moment().

To get it in a different language, use .local('xx') where xx is your language.

Then use .format()for however you want it.

Examples

moment().locale('en').format("dddd, MMMM Do YYYY, h:mm:ss a");
// returns "Thursday, September 3rd 2015, 3:13:29 pm"

moment().locale('fr').format("dddd, MMMM Do YYYY, h:mm:ss a");
// returns "jeudi, septembre 3 2015, 3:13:41 pm"

Upvotes: 1

Related Questions