You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Navigate to project folder and run `NativeScript-CLI` command `tns plugin add nativescript-intl`.
10
+
Navigate to project folder and run `NativeScript-CLI` command `tns plugin add nativescript-intl`.
11
+
12
+
This plugin provides similar to [Intl.js](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) API for date, time and number formatting on a mobile device (Android and iOS).
13
+
14
+
## How to use
15
+
16
+
```JavaScript
17
+
var intl =require("nativescript-intl");
18
+
var dateFormat =newintl.DateTimeFormat('en-US', {'year':'numeric', 'month':'short', 'day':'numeric'}).format(newDate(2016, 2, 23));
19
+
var numberFormat =newintl.NumberFormat('en-US', {'style':'currency', 'currency':'USD', 'currencyDisplay':'symbol'}).format(123456.789);
20
+
21
+
console.log("dateFormat: "+ dateFormat);
22
+
console.log("numberFormat: "+ numberFormat);
23
+
// prints Mar 23, 2016
24
+
// $123456.79
25
+
```
26
+
27
+
Since localization formatting is not exactly same on Android, iOS and [Intl.js](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Intl) there is another option to use this API.
var numberFormat =newintl.NumberFormat('en-US', {'style':'currency', 'currency':'USD', 'currencyDisplay':'symbol'}, '#,##0.00 ¤').format(123456.789);
35
+
36
+
console.log("dateFormat: "+ dateFormat);
37
+
console.log("numberFormat: "+ numberFormat);
38
+
// prints 2016 March 23, Wednesday 2016 12:35:40
39
+
// 123,456.79 $
40
+
```
41
+
42
+
> Omitting locale will use the current locale setting on device.
43
+
44
+
> Keep in mind that ICU versions differ accross device OS versions, so this plugin could produce different results on a different API level (Android) and OS version (iOS).
0 commit comments