react-util-tools 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +254 -0
- package/dist/index.cjs +943 -0
- package/dist/index.d.cts +154 -0
- package/dist/index.d.ts +154 -0
- package/dist/index.js +852 -0
- package/package.json +50 -0
- package/src/address/README.md +196 -0
- package/src/address/index.ts +41 -0
- package/src/date/README.md +539 -0
- package/src/date/index.ts +330 -0
- package/src/date/utc/README.md +779 -0
- package/src/date/utc/index.ts +374 -0
- package/src/decimal/README.md +425 -0
- package/src/decimal/index.ts +9 -0
- package/src/decimal/utils/README.md +474 -0
- package/src/decimal/utils/index.ts +244 -0
- package/src/device/README.md +441 -0
- package/src/device/index.ts +214 -0
- package/src/format/README.md +335 -0
- package/src/format/index.ts +189 -0
- package/src/index.ts +107 -0
- package/src/throttle/README.md +152 -0
- package/src/throttle/index.ts +83 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,539 @@
|
|
|
1
|
+
# Date 工具
|
|
2
|
+
|
|
3
|
+
基于 date-fns 封装的日期时间处理工具函数集合。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install your-package-name date-fns
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 使用方法
|
|
12
|
+
|
|
13
|
+
### 导入
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
formatDate,
|
|
18
|
+
formatDateOnly,
|
|
19
|
+
formatTimeOnly,
|
|
20
|
+
formatRelativeTime,
|
|
21
|
+
parseDate,
|
|
22
|
+
isValidDate,
|
|
23
|
+
getDaysDiff,
|
|
24
|
+
getHoursDiff,
|
|
25
|
+
getMinutesDiff,
|
|
26
|
+
addDaysToDate,
|
|
27
|
+
subDaysFromDate,
|
|
28
|
+
addMonthsToDate,
|
|
29
|
+
subMonthsFromDate,
|
|
30
|
+
getStartOfDay,
|
|
31
|
+
getEndOfDay,
|
|
32
|
+
getStartOfWeek,
|
|
33
|
+
getEndOfWeek,
|
|
34
|
+
getStartOfMonth,
|
|
35
|
+
getEndOfMonth,
|
|
36
|
+
getStartOfYear,
|
|
37
|
+
getEndOfYear,
|
|
38
|
+
isBeforeDate,
|
|
39
|
+
isAfterDate,
|
|
40
|
+
isSameDayDate,
|
|
41
|
+
getTimestamp,
|
|
42
|
+
getTimestampInSeconds
|
|
43
|
+
} from 'your-package-name'
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## API
|
|
47
|
+
|
|
48
|
+
### formatDate - 格式化日期
|
|
49
|
+
|
|
50
|
+
将日期格式化为指定格式的字符串。
|
|
51
|
+
|
|
52
|
+
**参数:**
|
|
53
|
+
- `date`: Date 对象、时间戳或日期字符串
|
|
54
|
+
- `formatStr`: 格式化字符串,默认 `'yyyy-MM-dd HH:mm:ss'`
|
|
55
|
+
|
|
56
|
+
**返回:** 格式化后的日期字符串
|
|
57
|
+
|
|
58
|
+
**示例:**
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
const now = new Date()
|
|
62
|
+
|
|
63
|
+
formatDate(now)
|
|
64
|
+
// "2024-11-10 15:30:45"
|
|
65
|
+
|
|
66
|
+
formatDate(now, 'yyyy年MM月dd日')
|
|
67
|
+
// "2024年11月10日"
|
|
68
|
+
|
|
69
|
+
formatDate(now, 'yyyy/MM/dd HH:mm')
|
|
70
|
+
// "2024/11/10 15:30"
|
|
71
|
+
|
|
72
|
+
// 使用时间戳
|
|
73
|
+
formatDate(1699612800000)
|
|
74
|
+
// "2023-11-10 16:00:00"
|
|
75
|
+
|
|
76
|
+
// 使用 ISO 字符串
|
|
77
|
+
formatDate('2024-11-10T15:30:45.000Z')
|
|
78
|
+
// "2024-11-10 23:30:45"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### formatDateOnly - 格式化为日期
|
|
82
|
+
|
|
83
|
+
只格式化日期部分,不含时间。
|
|
84
|
+
|
|
85
|
+
**示例:**
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
formatDateOnly(new Date())
|
|
89
|
+
// "2024-11-10"
|
|
90
|
+
|
|
91
|
+
formatDateOnly(1699612800000)
|
|
92
|
+
// "2023-11-10"
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### formatTimeOnly - 格式化为时间
|
|
96
|
+
|
|
97
|
+
只格式化时间部分,不含日期。
|
|
98
|
+
|
|
99
|
+
**示例:**
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
formatTimeOnly(new Date())
|
|
103
|
+
// "15:30:45"
|
|
104
|
+
|
|
105
|
+
formatTimeOnly(1699612800000)
|
|
106
|
+
// "16:00:00"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### formatRelativeTime - 格式化为相对时间
|
|
110
|
+
|
|
111
|
+
将日期格式化为相对于现在的时间描述。
|
|
112
|
+
|
|
113
|
+
**参数:**
|
|
114
|
+
- `date`: Date 对象、时间戳或日期字符串
|
|
115
|
+
- `locale`: 语言,`'zh'` 或 `'en'`,默认 `'zh'`
|
|
116
|
+
|
|
117
|
+
**示例:**
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
const now = new Date()
|
|
121
|
+
const fiveMinutesAgo = new Date(now.getTime() - 5 * 60 * 1000)
|
|
122
|
+
const twoHoursAgo = new Date(now.getTime() - 2 * 60 * 60 * 1000)
|
|
123
|
+
const yesterday = new Date(now.getTime() - 24 * 60 * 60 * 1000)
|
|
124
|
+
|
|
125
|
+
formatRelativeTime(fiveMinutesAgo)
|
|
126
|
+
// "5 分钟前"
|
|
127
|
+
|
|
128
|
+
formatRelativeTime(twoHoursAgo)
|
|
129
|
+
// "大约 2 小时前"
|
|
130
|
+
|
|
131
|
+
formatRelativeTime(yesterday)
|
|
132
|
+
// "1 天前"
|
|
133
|
+
|
|
134
|
+
// 英文
|
|
135
|
+
formatRelativeTime(fiveMinutesAgo, 'en')
|
|
136
|
+
// "5 minutes ago"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### parseDate - 解析日期字符串
|
|
140
|
+
|
|
141
|
+
将日期字符串解析为 Date 对象。
|
|
142
|
+
|
|
143
|
+
**参数:**
|
|
144
|
+
- `dateStr`: 日期字符串
|
|
145
|
+
- `formatStr`: 格式化字符串,默认 `'yyyy-MM-dd HH:mm:ss'`
|
|
146
|
+
|
|
147
|
+
**示例:**
|
|
148
|
+
|
|
149
|
+
```typescript
|
|
150
|
+
parseDate('2024-11-10 15:30:45')
|
|
151
|
+
// Date 对象
|
|
152
|
+
|
|
153
|
+
parseDate('2024/11/10', 'yyyy/MM/dd')
|
|
154
|
+
// Date 对象
|
|
155
|
+
|
|
156
|
+
parseDate('2024年11月10日', 'yyyy年MM月dd日')
|
|
157
|
+
// Date 对象
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### isValidDate - 验证日期是否有效
|
|
161
|
+
|
|
162
|
+
**示例:**
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
isValidDate(new Date())
|
|
166
|
+
// true
|
|
167
|
+
|
|
168
|
+
isValidDate('2024-11-10')
|
|
169
|
+
// true
|
|
170
|
+
|
|
171
|
+
isValidDate('invalid date')
|
|
172
|
+
// false
|
|
173
|
+
|
|
174
|
+
isValidDate(NaN)
|
|
175
|
+
// false
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### getDaysDiff - 计算天数差
|
|
179
|
+
|
|
180
|
+
计算两个日期之间相差的天数。
|
|
181
|
+
|
|
182
|
+
**示例:**
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
const date1 = new Date('2024-11-10')
|
|
186
|
+
const date2 = new Date('2024-11-15')
|
|
187
|
+
|
|
188
|
+
getDaysDiff(date2, date1)
|
|
189
|
+
// 5
|
|
190
|
+
|
|
191
|
+
getDaysDiff(date1, date2)
|
|
192
|
+
// -5
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### getHoursDiff - 计算小时差
|
|
196
|
+
|
|
197
|
+
**示例:**
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const date1 = new Date('2024-11-10 10:00:00')
|
|
201
|
+
const date2 = new Date('2024-11-10 15:30:00')
|
|
202
|
+
|
|
203
|
+
getHoursDiff(date2, date1)
|
|
204
|
+
// 5
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### getMinutesDiff - 计算分钟差
|
|
208
|
+
|
|
209
|
+
**示例:**
|
|
210
|
+
|
|
211
|
+
```typescript
|
|
212
|
+
const date1 = new Date('2024-11-10 10:00:00')
|
|
213
|
+
const date2 = new Date('2024-11-10 10:30:00')
|
|
214
|
+
|
|
215
|
+
getMinutesDiff(date2, date1)
|
|
216
|
+
// 30
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### addDaysToDate - 增加天数
|
|
220
|
+
|
|
221
|
+
**示例:**
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
const today = new Date('2024-11-10')
|
|
225
|
+
|
|
226
|
+
addDaysToDate(today, 7)
|
|
227
|
+
// 2024-11-17
|
|
228
|
+
|
|
229
|
+
addDaysToDate(today, -7)
|
|
230
|
+
// 2024-11-03
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### subDaysFromDate - 减少天数
|
|
234
|
+
|
|
235
|
+
**示例:**
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
const today = new Date('2024-11-10')
|
|
239
|
+
|
|
240
|
+
subDaysFromDate(today, 7)
|
|
241
|
+
// 2024-11-03
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### addMonthsToDate - 增加月数
|
|
245
|
+
|
|
246
|
+
**示例:**
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const date = new Date('2024-11-10')
|
|
250
|
+
|
|
251
|
+
addMonthsToDate(date, 2)
|
|
252
|
+
// 2025-01-10
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### subMonthsFromDate - 减少月数
|
|
256
|
+
|
|
257
|
+
**示例:**
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
const date = new Date('2024-11-10')
|
|
261
|
+
|
|
262
|
+
subMonthsFromDate(date, 2)
|
|
263
|
+
// 2024-09-10
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### getStartOfDay - 获取一天的开始时间
|
|
267
|
+
|
|
268
|
+
获取指定日期当天的 00:00:00。
|
|
269
|
+
|
|
270
|
+
**示例:**
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
const date = new Date('2024-11-10 15:30:45')
|
|
274
|
+
|
|
275
|
+
getStartOfDay(date)
|
|
276
|
+
// 2024-11-10 00:00:00
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
### getEndOfDay - 获取一天的结束时间
|
|
280
|
+
|
|
281
|
+
获取指定日期当天的 23:59:59。
|
|
282
|
+
|
|
283
|
+
**示例:**
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
const date = new Date('2024-11-10 15:30:45')
|
|
287
|
+
|
|
288
|
+
getEndOfDay(date)
|
|
289
|
+
// 2024-11-10 23:59:59
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### getStartOfWeek - 获取一周的开始时间
|
|
293
|
+
|
|
294
|
+
获取指定日期所在周的周一 00:00:00。
|
|
295
|
+
|
|
296
|
+
**示例:**
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
const date = new Date('2024-11-10') // 周日
|
|
300
|
+
|
|
301
|
+
getStartOfWeek(date)
|
|
302
|
+
// 2024-11-04 00:00:00 (周一)
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### getEndOfWeek - 获取一周的结束时间
|
|
306
|
+
|
|
307
|
+
获取指定日期所在周的周日 23:59:59。
|
|
308
|
+
|
|
309
|
+
**示例:**
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
const date = new Date('2024-11-10')
|
|
313
|
+
|
|
314
|
+
getEndOfWeek(date)
|
|
315
|
+
// 2024-11-10 23:59:59 (周日)
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### getStartOfMonth - 获取一个月的开始时间
|
|
319
|
+
|
|
320
|
+
**示例:**
|
|
321
|
+
|
|
322
|
+
```typescript
|
|
323
|
+
const date = new Date('2024-11-10')
|
|
324
|
+
|
|
325
|
+
getStartOfMonth(date)
|
|
326
|
+
// 2024-11-01 00:00:00
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### getEndOfMonth - 获取一个月的结束时间
|
|
330
|
+
|
|
331
|
+
**示例:**
|
|
332
|
+
|
|
333
|
+
```typescript
|
|
334
|
+
const date = new Date('2024-11-10')
|
|
335
|
+
|
|
336
|
+
getEndOfMonth(date)
|
|
337
|
+
// 2024-11-30 23:59:59
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
### getStartOfYear - 获取一年的开始时间
|
|
341
|
+
|
|
342
|
+
**示例:**
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const date = new Date('2024-11-10')
|
|
346
|
+
|
|
347
|
+
getStartOfYear(date)
|
|
348
|
+
// 2024-01-01 00:00:00
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### getEndOfYear - 获取一年的结束时间
|
|
352
|
+
|
|
353
|
+
**示例:**
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
const date = new Date('2024-11-10')
|
|
357
|
+
|
|
358
|
+
getEndOfYear(date)
|
|
359
|
+
// 2024-12-31 23:59:59
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### isBeforeDate - 判断日期是否在之前
|
|
363
|
+
|
|
364
|
+
**示例:**
|
|
365
|
+
|
|
366
|
+
```typescript
|
|
367
|
+
const date1 = new Date('2024-11-10')
|
|
368
|
+
const date2 = new Date('2024-11-15')
|
|
369
|
+
|
|
370
|
+
isBeforeDate(date1, date2)
|
|
371
|
+
// true
|
|
372
|
+
|
|
373
|
+
isBeforeDate(date2, date1)
|
|
374
|
+
// false
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### isAfterDate - 判断日期是否在之后
|
|
378
|
+
|
|
379
|
+
**示例:**
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
const date1 = new Date('2024-11-10')
|
|
383
|
+
const date2 = new Date('2024-11-15')
|
|
384
|
+
|
|
385
|
+
isAfterDate(date2, date1)
|
|
386
|
+
// true
|
|
387
|
+
|
|
388
|
+
isAfterDate(date1, date2)
|
|
389
|
+
// false
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### isSameDayDate - 判断是否是同一天
|
|
393
|
+
|
|
394
|
+
**示例:**
|
|
395
|
+
|
|
396
|
+
```typescript
|
|
397
|
+
const date1 = new Date('2024-11-10 10:00:00')
|
|
398
|
+
const date2 = new Date('2024-11-10 15:30:00')
|
|
399
|
+
const date3 = new Date('2024-11-11 10:00:00')
|
|
400
|
+
|
|
401
|
+
isSameDayDate(date1, date2)
|
|
402
|
+
// true
|
|
403
|
+
|
|
404
|
+
isSameDayDate(date1, date3)
|
|
405
|
+
// false
|
|
406
|
+
```
|
|
407
|
+
|
|
408
|
+
### getTimestamp - 获取当前时间戳(毫秒)
|
|
409
|
+
|
|
410
|
+
**示例:**
|
|
411
|
+
|
|
412
|
+
```typescript
|
|
413
|
+
getTimestamp()
|
|
414
|
+
// 1699612800000
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### getTimestampInSeconds - 获取当前时间戳(秒)
|
|
418
|
+
|
|
419
|
+
**示例:**
|
|
420
|
+
|
|
421
|
+
```typescript
|
|
422
|
+
getTimestampInSeconds()
|
|
423
|
+
// 1699612800
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## 实际应用场景
|
|
427
|
+
|
|
428
|
+
### 显示文章发布时间
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
import { formatRelativeTime, formatDate } from 'your-package-name'
|
|
432
|
+
|
|
433
|
+
const article = {
|
|
434
|
+
publishedAt: '2024-11-10T10:00:00.000Z'
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// 最近的显示相对时间
|
|
438
|
+
const now = new Date()
|
|
439
|
+
const publishDate = new Date(article.publishedAt)
|
|
440
|
+
const hoursDiff = (now.getTime() - publishDate.getTime()) / (1000 * 60 * 60)
|
|
441
|
+
|
|
442
|
+
if (hoursDiff < 24) {
|
|
443
|
+
console.log(formatRelativeTime(article.publishedAt))
|
|
444
|
+
// "2 小时前"
|
|
445
|
+
} else {
|
|
446
|
+
console.log(formatDate(article.publishedAt, 'yyyy-MM-dd'))
|
|
447
|
+
// "2024-11-10"
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
### 日期范围选择器
|
|
452
|
+
|
|
453
|
+
```typescript
|
|
454
|
+
import { getStartOfMonth, getEndOfMonth, formatDate } from 'your-package-name'
|
|
455
|
+
|
|
456
|
+
const today = new Date()
|
|
457
|
+
|
|
458
|
+
// 本月范围
|
|
459
|
+
const monthStart = getStartOfMonth(today)
|
|
460
|
+
const monthEnd = getEndOfMonth(today)
|
|
461
|
+
|
|
462
|
+
console.log(`本月:${formatDate(monthStart, 'yyyy-MM-dd')} 至 ${formatDate(monthEnd, 'yyyy-MM-dd')}`)
|
|
463
|
+
// "本月:2024-11-01 至 2024-11-30"
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
### 倒计时功能
|
|
467
|
+
|
|
468
|
+
```typescript
|
|
469
|
+
import { getDaysDiff, getHoursDiff, getMinutesDiff } from 'your-package-name'
|
|
470
|
+
|
|
471
|
+
const targetDate = new Date('2024-12-31 23:59:59')
|
|
472
|
+
const now = new Date()
|
|
473
|
+
|
|
474
|
+
const days = getDaysDiff(targetDate, now)
|
|
475
|
+
const hours = getHoursDiff(targetDate, now) % 24
|
|
476
|
+
const minutes = getMinutesDiff(targetDate, now) % 60
|
|
477
|
+
|
|
478
|
+
console.log(`距离新年还有 ${days} 天 ${hours} 小时 ${minutes} 分钟`)
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
### 日程提醒
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
import { isBeforeDate, isSameDayDate, formatDate } from 'your-package-name'
|
|
485
|
+
|
|
486
|
+
const events = [
|
|
487
|
+
{ title: '会议', date: '2024-11-10 14:00:00' },
|
|
488
|
+
{ title: '培训', date: '2024-11-11 09:00:00' }
|
|
489
|
+
]
|
|
490
|
+
|
|
491
|
+
const today = new Date()
|
|
492
|
+
|
|
493
|
+
events.forEach(event => {
|
|
494
|
+
const eventDate = new Date(event.date)
|
|
495
|
+
|
|
496
|
+
if (isSameDayDate(eventDate, today)) {
|
|
497
|
+
console.log(`今天有活动:${event.title}`)
|
|
498
|
+
} else if (isBeforeDate(today, eventDate)) {
|
|
499
|
+
console.log(`即将到来:${event.title} - ${formatDate(eventDate)}`)
|
|
500
|
+
}
|
|
501
|
+
})
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
### 数据统计时间范围
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
import { getStartOfWeek, getEndOfWeek, formatDate } from 'your-package-name'
|
|
508
|
+
|
|
509
|
+
const today = new Date()
|
|
510
|
+
|
|
511
|
+
// 本周数据
|
|
512
|
+
const weekStart = getStartOfWeek(today)
|
|
513
|
+
const weekEnd = getEndOfWeek(today)
|
|
514
|
+
|
|
515
|
+
fetchData({
|
|
516
|
+
startDate: formatDate(weekStart, 'yyyy-MM-dd'),
|
|
517
|
+
endDate: formatDate(weekEnd, 'yyyy-MM-dd')
|
|
518
|
+
})
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
## TypeScript 支持
|
|
522
|
+
|
|
523
|
+
完整的 TypeScript 类型支持。
|
|
524
|
+
|
|
525
|
+
```typescript
|
|
526
|
+
const formatted: string = formatDate(new Date())
|
|
527
|
+
const parsed: Date = parseDate('2024-11-10')
|
|
528
|
+
const isValid: boolean = isValidDate(new Date())
|
|
529
|
+
const diff: number = getDaysDiff(new Date(), new Date())
|
|
530
|
+
const timestamp: number = getTimestamp()
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
## 注意事项
|
|
534
|
+
|
|
535
|
+
- 所有函数都支持 Date 对象、时间戳(毫秒)和 ISO 日期字符串作为输入
|
|
536
|
+
- 使用 date-fns 作为底层库,确保安装了 `date-fns` 依赖
|
|
537
|
+
- 周的开始默认为周一(符合中国习惯)
|
|
538
|
+
- 相对时间默认使用中文,可通过参数切换为英文
|
|
539
|
+
- 所有返回 Date 对象的函数都返回新对象,不会修改原始日期
|