|
2 | 2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | 3 | // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'package:intl/date_symbol_data_local.dart'; |
5 | 6 | import 'package:intl/intl.dart'; |
6 | 7 |
|
7 | | -void main(List<String> arguments) { |
| 8 | +Future<void> main(List<String> arguments) async { |
8 | 9 | // These examples were all run with locale en_US. |
9 | 10 |
|
| 11 | + String? locale = 'en_US'; |
| 12 | + await initializeDateFormatting(locale); |
10 | 13 | final numberFormatters = [ |
11 | | - NumberFormat.compact(), // 2M |
12 | | - NumberFormat.compactCurrency(), // USD2M |
13 | | - NumberFormat.compactLong(), // 2 million |
14 | | - NumberFormat.compactSimpleCurrency(), // $2M |
15 | | - NumberFormat.currency(), // USD2,000,000.33 |
16 | | - NumberFormat.decimalPattern(), // 2,000,000.335 |
| 14 | + NumberFormat.compact(locale: locale), // 2M |
| 15 | + NumberFormat.compactCurrency(locale: locale), // USD2M |
| 16 | + NumberFormat.compactLong(locale: locale), // 2 million |
| 17 | + NumberFormat.compactSimpleCurrency(locale: locale), // $2M |
| 18 | + NumberFormat.currency(locale: locale), // USD2,000,000.33 |
| 19 | + NumberFormat.decimalPattern(locale), // 2,000,000.335 |
17 | 20 | NumberFormat.decimalPatternDigits(decimalDigits: 2), // 2,000,000.33 |
18 | 21 | NumberFormat.decimalPercentPattern(decimalDigits: 1), // 200,000,033.5% |
19 | | - NumberFormat.percentPattern(), // 200,000,033% |
20 | | - NumberFormat.scientificPattern(), // 2E6 |
21 | | - NumberFormat.simpleCurrency(), // $2,000,000.33 |
| 22 | + NumberFormat.percentPattern(locale), // 200,000,033% |
| 23 | + NumberFormat.scientificPattern(locale), // 2E6 |
| 24 | + NumberFormat.simpleCurrency(locale: locale), // $2,000,000.33 |
22 | 25 | ]; |
23 | 26 | print('Number formatting:'); |
24 | 27 | for (final formatter in numberFormatters) { |
25 | 28 | print(formatter.format(2000000.33454)); |
26 | 29 | } |
27 | 30 |
|
28 | 31 | final dateFormatters = [ |
29 | | - DateFormat.d(), // 26 |
30 | | - DateFormat.E(), // Wed |
31 | | - DateFormat.EEEE(), // Wednesday |
32 | | - DateFormat.EEEEE(), // W |
33 | | - DateFormat.LLL(), // Apr |
34 | | - DateFormat.LLLL(), // April |
35 | | - DateFormat.M(), // 4 |
36 | | - DateFormat.Md(), // 4/26 |
37 | | - DateFormat.MEd(), // Wed, 4/26 |
38 | | - DateFormat.MMM(), // Apr |
39 | | - DateFormat.MMMd(), // Apr 26 |
40 | | - DateFormat.MMMEd(), // Wed, Apr 26 |
41 | | - DateFormat.MMMM(), // April |
42 | | - DateFormat.MMMMd(), // April 26 |
43 | | - DateFormat.MMMMEEEEd(), // Wednesday, April 26 |
44 | | - DateFormat.QQQ(), // Q2 |
45 | | - DateFormat.QQQQ(), // 2nd quarter |
46 | | - DateFormat.y(), // 2023 |
47 | | - DateFormat.yM(), // 4/2023 |
48 | | - DateFormat.yMd(), // 4/26/2023 |
49 | | - DateFormat.yMEd(), // Wed, 4/26/2023 |
50 | | - DateFormat.yMMM(), // Apr 2023 |
51 | | - DateFormat.yMMMd(), // Apr 26, 2023 |
52 | | - DateFormat.yMMMEd(), // Wed, Apr 26, 2023 |
53 | | - DateFormat.yMMMM(), // April 2023 |
54 | | - DateFormat.yMMMMd(), // April 26, 2023 |
55 | | - DateFormat.yMMMMEEEEd(), // Wednesday, April 26, 2023 |
56 | | - DateFormat.yQQQ(), // Q2 2023 |
57 | | - DateFormat.yQQQQ(), // 2nd quarter 2023 |
58 | | - DateFormat.H(), // 05 |
59 | | - DateFormat.Hm(), // 05:24 |
60 | | - DateFormat.Hms(), // 05:24:22 |
61 | | - DateFormat.j(), // 5 AM |
62 | | - DateFormat.jm(), // 5:24 AM |
63 | | - DateFormat.jms(), // 5:24:22 AM |
| 32 | + DateFormat.d(locale), // 26 |
| 33 | + DateFormat.E(locale), // Wed |
| 34 | + DateFormat.EEEE(locale), // Wednesday |
| 35 | + DateFormat.EEEEE(locale), // W |
| 36 | + DateFormat.LLL(locale), // Apr |
| 37 | + DateFormat.LLLL(locale), // April |
| 38 | + DateFormat.M(locale), // 4 |
| 39 | + DateFormat.Md(locale), // 4/26 |
| 40 | + DateFormat.MEd(locale), // Wed, 4/26 |
| 41 | + DateFormat.MMM(locale), // Apr |
| 42 | + DateFormat.MMMd(locale), // Apr 26 |
| 43 | + DateFormat.MMMEd(locale), // Wed, Apr 26 |
| 44 | + DateFormat.MMMM(locale), // April |
| 45 | + DateFormat.MMMMd(locale), // April 26 |
| 46 | + DateFormat.MMMMEEEEd(locale), // Wednesday, April 26 |
| 47 | + DateFormat.QQQ(locale), // Q2 |
| 48 | + DateFormat.QQQQ(locale), // 2nd quarter |
| 49 | + DateFormat.y(locale), // 2023 |
| 50 | + DateFormat.yM(locale), // 4/2023 |
| 51 | + DateFormat.yMd(locale), // 4/26/2023 |
| 52 | + DateFormat.yMEd(locale), // Wed, 4/26/2023 |
| 53 | + DateFormat.yMMM(locale), // Apr 2023 |
| 54 | + DateFormat.yMMMd(locale), // Apr 26, 2023 |
| 55 | + DateFormat.yMMMEd(locale), // Wed, Apr 26, 2023 |
| 56 | + DateFormat.yMMMM(locale), // April 2023 |
| 57 | + DateFormat.yMMMMd(locale), // April 26, 2023 |
| 58 | + DateFormat.yMMMMEEEEd(locale), // Wednesday, April 26, 2023 |
| 59 | + DateFormat.yQQQ(locale), // Q2 2023 |
| 60 | + DateFormat.yQQQQ(locale), // 2nd quarter 2023 |
| 61 | + DateFormat.H(locale), // 05 |
| 62 | + DateFormat.Hm(locale), // 05:24 |
| 63 | + DateFormat.Hms(locale), // 05:24:22 |
| 64 | + DateFormat.j(locale), // 5 AM |
| 65 | + DateFormat.jm(locale), // 5:24 AM |
| 66 | + DateFormat.jms(locale), // 5:24:22 AM |
64 | 67 | ]; |
65 | 68 | print('Date formatting:'); |
66 | 69 | for (final formatter in dateFormatters) { |
|
0 commit comments