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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With