date_format.dart
5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/// Outputs year as four digits
///
/// Example:
/// formatDate(new DateTime(2018,8,31), [yMDW]);
/// // => Today
const String yMDW = 'ymdw';
///
/// Example:
/// formatDate(new DateTime(1989), [yyyy]);
/// // => 1989
const String yyyy = 'yyyy';
/// Outputs year as two digits
///
/// Example:
/// formatDate(new DateTime(1989), [yy]);
/// // => 89
const String yy = 'yy';
/// Outputs month as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 11), [mm]);
/// // => 11
/// formatDate(new DateTime(1989, 5), [mm]);
/// // => 05
const String mm = 'mm';
/// Outputs month compactly
///
/// Example:
/// formatDate(new DateTime(1989, 11), [mm]);
/// // => 11
/// formatDate(new DateTime(1989, 5), [m]);
/// // => 5
const String m = 'm';
/// Outputs month as long name
///
/// Example:
/// formatDate(new DateTime(1989, 2), [mM]);
/// // => february
const String mM = 'MM';
/// Outputs month as short name
///
/// Example:
/// formatDate(new DateTime(1989, 2), [M]);
/// // => feb
const String M = 'M';
/// Outputs day as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 2, 21), [dd]);
/// // => 21
/// formatDate(new DateTime(1989, 2, 5), [dd]);
/// // => 05
const String dd = 'dd';
/// Outputs day compactly
///
/// Example:
/// formatDate(new DateTime(1989, 2, 21), [d]);
/// // => 21
/// formatDate(new DateTime(1989, 2, 5), [d]);
/// // => 5
const String d = 'd';
/// Outputs week in month
///
/// Example:
/// formatDate(new DateTime(1989, 2, 21), [w]);
/// // => 4
const String w = 'w';
/// Outputs week in year as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 12, 31), [W]);
/// // => 53
/// formatDate(new DateTime(1989, 2, 21), [W]);
/// // => 08
const String wW = 'WW';
/// Outputs week in year compactly
///
/// Example:
/// formatDate(new DateTime(1989, 2, 21), [W]);
/// // => 8
const String W = 'W';
/// Outputs week day as long name
///
/// Example:
/// formatDate(new DateTime(2018, 1, 14), [D]);
/// // => sun
const String D = 'D';
/// Outputs hour (0 - 11) as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15), [hh]);
/// // => 03
const String hh = 'hh';
/// Outputs hour (0 - 11) compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15), [h]);
/// // => 3
const String h = 'h';
/// Outputs hour (0 to 23) as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15), [hH]);
/// // => 15
const String hH = 'HH';
/// Outputs hour (0 to 23) compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 5), [H]);
/// // => 5
const String H = 'H';
/// Outputs minute as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40), [nn]);
/// // => 40
/// formatDate(new DateTime(1989, 02, 1, 15, 4), [nn]);
/// // => 04
const String nn = 'nn';
/// Outputs minute compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 4), [n]);
/// // => 4
const String n = 'n';
/// Outputs second as two digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10), [ss]);
/// // => 10
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 5), [ss]);
/// // => 05
const String ss = 'ss';
/// Outputs second compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 5), [s]);
/// // => 5
const String s = 's';
/// Outputs millisecond as three digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 999), [sSS]);
/// // => 999
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 99), [SS]);
/// // => 099
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0), [SS]);
/// // => 009
const String sSS = 'SSS';
/// Outputs millisecond compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 999), [sSS]);
/// // => 999
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 99), [SS]);
/// // => 99
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 9), [SS]);
/// // => 9
const String S = 'S';
/// Outputs microsecond as three digits
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 999), [uuu]);
/// // => 999
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 99), [uuu]);
/// // => 099
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 9), [uuu]);
/// // => 009
const String uuu = 'uuu';
/// Outputs millisecond compactly
///
/// Example:
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 999), [u]);
/// // => 999
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 99), [u]);
/// // => 99
/// formatDate(new DateTime(1989, 02, 1, 15, 40, 10, 0, 9), [u]);
/// // => 9
const String u = 'u';
/// Outputs if hour is AM or PM
///
/// Example:
/// print(formatDate(new DateTime(1989, 02, 1, 5), [am]));
/// // => AM
/// print(formatDate(new DateTime(1989, 02, 1, 15), [am]));
/// // => PM
const String am = 'am';
/// Outputs timezone as time offset
///
/// Example:
///
const String z = 'z';
const String Z = 'Z';
String digits(int value, int length) {
return '$value'.padLeft(length, "0");
}
int dayInYear(DateTime date) =>
date.difference(DateTime(date.year, 1, 1)).inDays;