自动化立体仓库 - WMS系统
#
lsh
2025-04-07 644054957e6c926cee03cf99b1869ae2b1523ff4
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
package com.zy.common.utils;
 
import com.core.common.DateUtils;
 
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.Date;
 
public class YyyyMmddUtils {
    public static String convertYyyyMMdd() {
        return DateUtils.convert(new Date(), "MMdd");
    }
 
    public static String convertYyyyMMdd(Date date) {
        return DateUtils.convert(date, "MMdd");
    }
 
    public static long convertYyyyMMdd100000() {
        String convert = convertYyyyMMdd();
        return 100000*(Long.valueOf(convert));
    }
 
    public static long convertYyyyMMdd100000(Date date) {
        String convert = convertYyyyMMdd(date);
        return 100000*(Long.valueOf(convert));
    }
 
    public static LocalTime convertToBeijingTime(Date date) {
        return date.toInstant()                       // Date -> Instant(时间戳)
                .atZone(ZoneId.of("Asia/Shanghai"))    // 绑定北京时区(UTC+8)
                .toLocalTime();                       // 提取时间部分
    }
 
    public static LocalDateTime convert(Date date) {
        return date.toInstant()                     // 将 Date 转换为 Instant(时间戳)
                .atZone(ZoneId.systemDefault())     // 绑定系统默认时区
                .toLocalDateTime();                 // 提取无时区的日期时间
    }
 
    // 基于 java.time 的实现(线程安全且简洁)
    public static long getSecondsOfDay(Date date) {
        // 1. 获取当天零点时间(系统时区)
        LocalDateTime startOfDay = LocalDateTime.now().with(LocalTime.MIN);
 
        // 2. 获取当前时间
        LocalDateTime currentTime = convert(date);
 
        // 3. 计算时间差的秒数
        long secondsSinceMidnight = Duration.between(startOfDay, currentTime).getSeconds();
        return secondsSinceMidnight;
    }
 
    // 原方法改造(带 Date 参数)
    public static long convertYyyyMMdd100000ioPri(Date data) {
        long ioPri = convertYyyyMMdd100000(data);
        long secondsOfDay = getSecondsOfDay(data);
        System.out.println(secondsOfDay);
        return ioPri + (1000000 - secondsOfDay);
    }
 
    // 重载方法(兼容无 Date 参数的调用)
    public static long convertYyyyMMdd1000000ioPri() {
        return convertYyyyMMdd100000ioPri(new Date());
    }
 
    // 重载方法(兼容无 Date 参数的调用)
    public static Integer convertPri(Date date) {
        long datePri = convertYyyyMMdd100000ioPri(date);
        return (int)datePri;
    }
 
    public static void main(String[] args) {
        Date now = new Date();
        long result = YyyyMmddUtils.convertYyyyMMdd100000ioPri(now);
        System.out.println("计算值:" + result);
        System.out.println("计算值:" + (int)result);
    }
}