brosua
brosua

Reputation: 56

Ionic: date pipe and local date

I want to print creation dates for news posts. I used the date pipe of angular.

{{news.created_at | date:'shortDate'}}

I saw after testing on my smartphone (language: german), that the dates are in english format (e.g. 10/26/2017).

Is there an option to format date in ionic according to the device language?

Upvotes: 4

Views: 10020

Answers (1)

Black Mamba
Black Mamba

Reputation: 15595

You can apply date filter like this in your required format.This is helpful method if your app is mostly for some particular countries you can change date format for them and let other countries pick up the default case.

<p>Date = {{ today | date :  "dd.MM.y" }}</p>

Consider This link for more info

All you need to do is: Use

navigator.language || navigator.userLanguage

To get the device language Then based on language create a date variable to store the format for that language like $scope.dateFormat = "dd.MM.y"

And then use it in your html like | date : dateFormat

Upvotes: 11

Related Questions