Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 448
brosua Avatar asked Jan 29 '23 07:01

brosua


1 Answers

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

like image 196
Black Mamba Avatar answered Feb 03 '23 07:02

Black Mamba