Search code examples
angulardatetranslate

How to translate a date in Angular


I'm using ng-translate to translate my app. But I'm stuck on translating a string date :

  • If it's in french, I would see 'Le 24 décembre à 13h'
  • If it's in english, I would see 'December 24th at 1pm'

How can I do such a thing ? I also have to translate it in german


Solution

  • You can install momentjs:

    npm install moment --save
    import * as moment from 'moment';
    

    Next use Moment Multiple Locale Support:

    moment().format('LL');
    

    HINT: According to your locale, you have a better format:

    moment().format('ll');   // 4 avr. 2018 for french locale <br>
    moment().format('LL');   // April 4, 2018 for US English <br>
    

    Hope I help!