feiyu02
2025-09-17 b330e57051e54789eb83d10dc58c4d9d10c608e1
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
import dayjs from 'dayjs';
 
export default {
  format(date, template) {
    return dayjs(date).format(template);
  },
 
  formatH(date) {
    if (date) {
      return this.format(date, 'HH:mm:ss');
    } else {
      return '--:--:--';
    }
  },
 
  formatYM(date) {
    if (date) {
      return this.format(date, 'YYYY-MM');
    } else {
      return '----/--';
    }
  },
 
  formatYMD(date) {
    if (date) {
      return this.format(date, 'YYYY-MM-DD');
    } else {
      return '----/--/--';
    }
  },
 
  formatYMDH(date) {
    if (date) {
      return this.format(date, 'YYYY-MM-DD HH:mm:ss');
    } else {
      return '----/--/-- --:--:--';
    }
  },
 
  formatDateFromExcel(num, format) {
    const old = num - 1;
    const t = Math.round((old - Math.floor(old)) * 24 * 60 * 60);
    const time = new Date(1900, 0, old, 0, 0, t);
    const year = time.getFullYear();
    const month = time.getMonth() + 1;
    const date = time.getDate();
    return dayjs(
      year +
      format +
      (month < 10 ? '0' + month : month) +
      format +
      (date < 10 ? '0' + date : date)
    );
  }
};