Search code examples
angularjsangularjs-scopemomentjsangular-moment

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.


Solution

  • 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"