java工具类

3/8/2023

# RedisService

import redis.clients.jedis.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author apophis
 * @ClassName RedisService
 * @date 2022/2/24
 * @desc 工程介绍
 */
public class RedisService {
    /**
     * 批量获取hash key里的数据
     *
     * @param jedis
     * @param key
     * @return
     */
    public static List<Map.Entry<String, String>> pullAll(Jedis jedis, String key) {
        String cursor = String.valueOf(0);
        ScanParams params = new ScanParams();
        // 由于编译后,感觉不对劲,因为特地使用isFir
        boolean isFir = true;
        List<Map.Entry<String, String>> total = new ArrayList<>();
        while (isFir || Integer.parseInt(cursor) > 0) {
            isFir = false;
            params.count(5000);
            ScanResult<Map.Entry<String, String>> result = jedis.hscan(key, cursor, params);
            cursor = result.getCursor();
            total.addAll(result.getResult());
        }
        return total;
    }

    /**
     * 通过管道批量读取
     *
     * @param jedis
     * @param key
     * @return
     */
    public static Map<String, String> pipelinePullAll(Jedis jedis, String key) {
        try (Pipeline p = jedis.pipelined()) {
            Response<Map<String, String>> response = p.hgetAll(key);
            p.sync();
            return response.get();
        }
    }

    /**
     * 通过管道批量写入
     *
     * @param jedis
     * @param key
     * @param map
     * @return
     */
    public static void pipelinePush(Jedis jedis, String key, Map<String, String> map) {
        try (Pipeline p = jedis.pipelined()) {
            for (Map.Entry<String, String> entry : map.entrySet()) p.hset(key, entry.getKey(), entry.getValue());
            p.sync();
        }
    }
}
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

# UrlService

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * @author apophis
 * @ClassName UrlService
 * @date 2021/6/15
 * @desc 工程介绍
 */
@Setter
@Getter
@NoArgsConstructor
@Slf4j
public abstract class UrlService {
    private String url;
    private Map<String, String> urlMap;

    public UrlService(String url) {
        this.url = url;
    }

    public UrlService(String preUrl, Map<String, String> urlMap, String... options) {
        this.url = (preUrl.endsWith("?") ? preUrl : preUrl + "?") + String.join("&", options);
        this.urlMap = urlMap;
    }

    public UrlService(String preUrl, String... options) {
        this.url = (preUrl.endsWith("?") ? preUrl : preUrl + "?") + String.join("&", options);
    }

    public String getResp() {
        StringBuilder builder = new StringBuilder();
        InputStream is = null;
        BufferedReader br = null;
        HttpURLConnection urlcon = null;
        try {
            URL url = new URL(this.url);
            urlcon = (HttpURLConnection) url.openConnection();
            if (this.urlMap != null && this.urlMap.size() != 0)
                for (Map.Entry<String, String> entry : this.urlMap.entrySet())
                    urlcon.setRequestProperty(entry.getKey(), entry.getValue());
            urlcon.connect();
            if (urlcon.getResponseCode() == 200) {
                is = urlcon.getInputStream();
                br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8));
                String s;
                while ((s = br.readLine()) != null) {
                    String format = this.format(s);
                    if (format != null && format.length() != 0) builder.append(format);
                }
            }
        } catch (Exception e) {
            UrlService.log.error("getResp,errData={}", this.url);
            UrlService.log.error("getResp", e);
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
                is = null;
            }
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
                br = null;
            }
            if (urlcon != null) {
                urlcon.disconnect();
                urlcon = null;
            }
        }
        return builder.toString();
    }

    public abstract String format(String line);
}
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

# FileUtils

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author apophis
 * @File FileUtils
 * @Time 2021/7/23 21:37
 * @Description 工程描述
 */
public class FileUtils {
    public static List<String> readLines(String path) {
        String line = null;
        List<String> lineList = new ArrayList<>();
        try (BufferedReader br = new BufferedReader(new FileReader(path))) {
            while ((line = br.readLine()) != null) lineList.add(line);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return lineList;
    }

    public static void writeFile(String path, List<String> contentList) throws Exception {
        FileUtils.createNewFile(path);
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {
            for (String line : contentList) {
                bw.write(line);
                bw.newLine();
            }
            bw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void writeFile(String path, String content) throws Exception {
        FileUtils.createNewFile(path);
        try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {
            bw.write(content);
            bw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void createPath(String path) throws Exception {
        FileUtils.createPath(new File(path));
    }

    public static void createPath(File f) throws Exception {
        if (!f.exists()) if (!f.mkdirs()) throw new Exception("mkdir file failed!");
    }

    public static void deleteFile(String path) throws Exception {
        File file = new File(path);
        int deleteOk = -1;
        if (file.exists()) deleteOk = file.delete() ? 0 : 1;
        if (deleteOk == 1) throw new Exception("delete file failed");
    }

    public static void createNewFile(String path) throws Exception {
        File file = new File(path);
        FileUtils.createPath(file.getParentFile());

        int deleteOk = -1;
        int newOk = -1;
        if (file.exists()) {
            deleteOk = file.delete() ? 0 : 1;
            newOk = file.createNewFile() ? 0 : 1;
        }
        if (deleteOk == 1 || newOk == 1) throw new Exception("create new file failed");
    }
}
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

# DBService

package com.example.person.bigdata.common.service;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.Builder;

import java.sql.*;
import java.util.concurrent.TimeUnit;


/**
 * @Author apophis
 * @File DBUtil
 * @Time 2023/9/11 16:15
 * @Description 工程描述
 */
public class DBService {
    public static final String DRIVER_MYSQL = "com.mysql.cj.jdbc.Driver";
    public static final String DRIVER_HIVE = "org.apache.hive.jdbc.HiveDriver";
    public static final String DRIVER_TDENGINE = "com.taosdata.jdbc.rs.RestfulDriver";

    public static void release(Connection connection, PreparedStatement preparedStatement, ResultSet resultSet) {
        release(connection, preparedStatement);
        release(resultSet);
    }

    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------

    public static void release(Connection connection, PreparedStatement preparedStatement) {
        release(connection);
        release(preparedStatement);
    }

    public static void release(Connection connection, Statement statement) {
        release(connection);
        release(statement);
    }

    private static void release(Connection connection) {
        if (connection != null) {
            try {
                connection.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            connection = null;
        }
    }

    private static void release(PreparedStatement preparedStatement) {
        if (preparedStatement != null) {
            try {
                preparedStatement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            preparedStatement = null;
        }
    }

    private static void release(ResultSet resultSet) {
        if (resultSet != null) {
            try {
                resultSet.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            resultSet = null;
        }
    }

    private static void release(Statement statement) {
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            statement = null;
        }
    }

    @Builder
    public static class DBServiceBuilder {
        private static final boolean DEFAULT_AUTOCOMMIT = true;
        private static final boolean DEFAULT_READONLY = true;
        private static final long DEFAULT_CONNECTION_TIMEOUT = TimeUnit.SECONDS.toMillis(30);
        private static final long DEFAULT_IDLE_TIMEOUT = TimeUnit.SECONDS.toMillis(10);
        private static final long DEFAULT_MAX_LIFETIME = TimeUnit.SECONDS.toMillis(30);
        private static final int DEFAULT_MAXIMUM_POOL_SIZE = 10;
        private static final int DEFAULT_MINIMUM_IDLE = 5;
        private String jdbcUrl;
        private String driverName;
        private String username;
        private String password;
        private Boolean autoCommit;
        private Boolean readOnly;
        private Long connectionTimeout;
        private Long idleTimeout;
        private Long maxLifetime;
        private Integer maximumPoolSize;
        private Integer minimumIdle;

        public HikariDataSource getDataSource() {
            HikariConfig config = new HikariConfig();
            config.setDriverClassName(this.driverName);
            config.setJdbcUrl(this.jdbcUrl);
            config.setUsername(this.username);
            config.setPassword(this.password);
            config.addDataSourceProperty("cachePrepStmts", "true"); // 是否自定义配置,为true时下面两个参数才生效
            config.addDataSourceProperty("prepStmtCacheSize", "250"); // 缓存的 prepare 语句数目,默认25,官方推荐250-500
            config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); // 单条语句最大长度默认256,官方推荐2048
            config.addDataSourceProperty("useServerPrepStmts", "true"); // 新版本MySQL支持服务器端准备,开启能够得到显著性能提升
            config.addDataSourceProperty("useLocalSessionState", "true");
            config.addDataSourceProperty("useLocalTransactionState", "true");
            config.addDataSourceProperty("rewriteBatchedStatements", "true");
            config.addDataSourceProperty("cacheResultSetMetadata", "true");
            config.addDataSourceProperty("cacheServerConfiguration", "true");
            config.addDataSourceProperty("elideSetAutoCommits", "true");
            config.addDataSourceProperty("maintainTimeStats", "false");
            config.setConnectionTestQuery("select 1");
            // 自动提交从池中返回的连接
            config.setAutoCommit(this.autoCommit == null ? DEFAULT_AUTOCOMMIT : this.autoCommit);
            config.setReadOnly(this.readOnly == null ? DEFAULT_READONLY : this.readOnly);
            // 等待来自池的连接的最大毫秒数
            config.setConnectionTimeout(this.connectionTimeout == null ? DEFAULT_CONNECTION_TIMEOUT : this.connectionTimeout);
            // 连接允许在池中闲置的最长时间,毫秒
            config.setIdleTimeout(this.idleTimeout == null ? DEFAULT_IDLE_TIMEOUT : this.idleTimeout);
            // 池中连接最长生命周期,毫秒
            config.setMaxLifetime(this.maxLifetime == null ? DEFAULT_MAX_LIFETIME : this.maxLifetime);
            // 池中最大连接数,包括闲置和使用中的连接 10
            config.setMaximumPoolSize(this.maximumPoolSize == null ? DEFAULT_MAXIMUM_POOL_SIZE : this.maximumPoolSize);
            // 池中维护的最小空闲连接数 5
            config.setMinimumIdle(this.minimumIdle == null ? DEFAULT_MINIMUM_IDLE : this.minimumIdle);
            return new HikariDataSource(config);
        }

    }
}
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

# JsonUtils

import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.annotation.JsonInclude;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationFeature;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode;
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author apophis
 * @ClassName JsonUtils
 * @date 2021/3/5
 * @desc 工程介绍
 */
public class JsonUtils {
    private static final ObjectMapper mapper = new ObjectMapper()
            .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
            // 属性为NULL 不序列化
            .setSerializationInclusion(JsonInclude.Include.NON_NULL);

    public static ObjectMapper mapper() {
        return JsonUtils.mapper;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

# MathUtils

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author apophis
 * @ClassName MathUtils
 * @date 2022/2/28
 * @desc 工程介绍
 */
public class MathUtils {
    /**
     * 默认保留2位小数
     *
     * @param val
     * @return
     */
    public static BigDecimal round(Double val) {
        // 使用doubleValue时 若传入0D,会返回0.0
        // return MathUtils.round(BigDecimal.valueOf(val), 2).doubleValue();
        return MathUtils.round(val, 2);
    }

    /**
     * 默认保留2位小数
     *
     * @param val
     * @return
     */
    public static BigDecimal round(BigDecimal val) {
        return MathUtils.round(val, 2);
    }

    public static BigDecimal round(BigDecimal val, int scale) {
        try {
            return val.setScale(scale, RoundingMode.HALF_UP);
        } catch (Exception ignored) {
        }
        return null;
    }

    public static BigDecimal round(Double val, int scale) {
        try {
            return BigDecimal.valueOf(val).setScale(scale, RoundingMode.HALF_UP);
        } catch (Exception ignored) {
        }
        return null;
    }
    // commons-lang3 自带
    // public static BigDecimal round(BigDecimal val, int scale) {
    //     BigDecimal rs = NumberUtils.toScaledBigDecimal(val, scale, RoundingMode.HALF_UP);
    //     return BigDecimal.ZERO.equals(rs) ? null : rs;
    // }
    //
    // public static BigDecimal round(Double val, int scale) {
    //     BigDecimal rs = NumberUtils.toScaledBigDecimal(val, scale, RoundingMode.HALF_UP);
    //     return BigDecimal.ZERO.equals(rs) ? null : rs;
    // }

    public static void main(String[] args) {
        BigDecimal a = new BigDecimal("3.6666666666");
        BigDecimal b = BigDecimal.valueOf(-3.6666666666);
        System.out.println(MathUtils.round(b));
        System.out.println("" + MathUtils.round(0D));
        System.out.println(MathUtils.round(3.777777777777));
    }
}
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

# PropertiesUtils

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author apophis
 * @ClassName PropertiesUtils
 * @date 2021/5/13
 * @desc 工程介绍
 */
public class PropertiesUtils {
    public static Properties read(String file) {
        Properties p = new Properties();
        try (InputStream in = new BufferedInputStream(new FileInputStream(file))) {
            p.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return p;
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

# RangeUtils

public enum Range {
    NULL(), MATCH(), NOT_MATCH()
}
1
2
3
import Range;

/**
 * @Author apophis
 * @File RangeUtils
 * @Time 2022/1/16 15:11
 * @Description 工程描述
 */
public class RangeUtils {
    public static Range range(double num, double eq) {
        return num == eq ? Range.MATCH : Range.NOT_MATCH;
    }

    public static Range range(double num, Double lower, Double upper, boolean containLower, boolean containUpper) {
        Range r = Range.NOT_MATCH;
        boolean isLow = lower == null;
        if (lower != null) isLow = num > lower;
        if (!isLow && containLower) isLow = num >= lower;


        boolean isUp = upper == null;
        if (upper != null) isUp = num < upper;
        if (!isUp && containUpper) isUp = num <= upper;
        if (isLow && isUp) r = Range.MATCH;
        return r;
    }
}
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

# StringUtils

/**
 * @author apophis
 * @ClassName StringUtils
 * @date 2022/1/12
 * @desc 工程介绍
 */
public class StringUtils {
    private static final String DEF_V = "";

    /**
     * @param str
     * @return 判断字符串是否为null或空或全是空白字符
     */
    public static boolean isBlank(String str) {
        if (str == null || str.length() == 0) return true;

        final int len = str.length();
        for (int i = 0; i < len; i++) if (!Character.isWhitespace(str.charAt(i))) return false;
        return true;
    }

    /**
     * 写log用
     *
     * @param v
     * @return
     */
    public static String convertV(Boolean v) {
        return StringUtils.convertV(v, DEF_V);
    }

    public static String convertV(Double v) {
        return StringUtils.convertV(v, DEF_V);
    }

    public static String convertV(Double v, String defaultValue) {
        return v == null ? defaultValue : DEF_V + v;
    }

    public static String convertV(String v) {
        return StringUtils.convertV(v, DEF_V);
    }

    public static String convertV(Long v) {
        return StringUtils.convertV(v, DEF_V);
    }

    public static String convertV(Integer v) {
        return StringUtils.convertV(v, DEF_V);
    }

    public static String convertV(Boolean v, String defaultValue) {
        return v == null ? defaultValue : DEF_V + v;
    }

    public static String convertV(String v, String defaultValue) {
        return StringUtils.isBlank(v) ? defaultValue : v;
    }

    public static String convertV(Long v, String defaultValue) {
        return v == null ? defaultValue : DEF_V + v;
    }

    public static String convertV(Integer v, String defaultValue) {
        return v == null ? defaultValue : DEF_V + v;
    }
}
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

# TimeUtils

import java.time.*;
import java.time.format.DateTimeFormatter;

/**
 * @author apophis
 * @ClassName TimeUtils
 * @date 2021/3/16
 * @desc 工程介绍
 */
public class TimeUtils {
    private static final ZoneId zoneId = ZoneId.of("Asia/Shanghai");
    private static final ZoneOffset zoneOffset = ZoneOffset.of("+8");
    private static final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    private static final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

    public static void main(String[] args) {
        // UTC时区 2021-03-16T02:37:34.343Z
        Instant instant = Instant.now();
        System.out.println(instant);

        // 偏移量运算 2021-03-16T10:37:34.343+08:00
        OffsetDateTime offsetDateTime = instant.atOffset(ZoneOffset.ofHours(8));
        System.out.println(offsetDateTime);

        Instant instant1 = Instant.now();
        LocalTime localTime1 = LocalTime.now();
        LocalDateTime localDateTime1 = LocalDateTime.now();  // 2021-03-16T10:30:45.883
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        Instant instant2 = Instant.now();
        LocalTime localTime2 = LocalTime.now();
        LocalDateTime localDateTime2 = LocalDateTime.now();
        // 时间间隔
        Duration duration = TimeUtils.timeDiff(instant1, instant2);
        System.out.println(duration.toMillis());
        Duration duration2 = Duration.between(localDateTime1, localDateTime2);
        System.out.println(duration2.toMillis());
        // 日期间隔
        Duration duration1 = Duration.between(localTime1, localTime2);
        System.out.println(duration1.toMillis());

        // 加三年并减三月 2023-12-16T10:30:45.883
        LocalDateTime localDateTime = localDateTime1.plusYears(3).minusMonths(3);
        System.out.println(localDateTime);


        // 2023-12-16T10:31:50.863
        // 2023
        System.out.println(localDateTime.getYear());
        // 12
        System.out.println(localDateTime.getMonthValue());
        // 16
        System.out.println(localDateTime.getDayOfMonth());
        // 10
        System.out.println(localDateTime.getHour());
        // 31
        System.out.println(localDateTime.getMinute());
        // 50
        System.out.println(localDateTime.getSecond());
        System.out.println(TimeUtils.now());

    }

    public static LocalDateTime dateStrToDate(String timeStr) {
        return LocalDateTime.parse(timeStr, DateTimeFormatter.ISO_DATE);
    }

    public static LocalDateTime timeStrToDate(String timeStr) {
        return LocalDateTime.parse(timeStr, TimeUtils.dateTimeFormatter);
    }

    public static String dateToTimeStr(LocalDateTime localDateTime) {
        return TimeUtils.dateToCusTom(localDateTime, TimeUtils.dateTimeFormatter);
    }

    public static String dateToDateStr(LocalDateTime localDateTime) {
        return TimeUtils.dateToCusTom(localDateTime, TimeUtils.dateFormatter);
    }


    public static Duration timeDiff(Instant instant1, Instant instant2) {
        return Duration.between(instant1, instant2);
    }

    public static Duration timeDiff(LocalTime localTime1, LocalTime localTime2) {
        return Duration.between(localTime1, localTime2);
    }

    /**
     * 时间戳转换为Date
     *
     * @param timestamp
     * @return
     */
    public static LocalDateTime timestampToDate(long timestamp) {
        return Instant.ofEpochMilli(timestamp).atZone(TimeUtils.zoneId).toLocalDateTime();
    }

    public static ZoneId zoneId() {
        return TimeUtils.zoneId;
    }

    public static String timestampToDateStr(long timestamp) {
        return TimeUtils.dateToDateStr(TimeUtils.timestampToDate(timestamp));
    }

    public static String timestampToTimeStr(long timestamp) {
        return TimeUtils.dateToTimeStr(TimeUtils.timestampToDate(timestamp));
    }

    public static String now() {
        return TimeUtils.dateToTimeStr(LocalDateTime.now());
    }

    public static long dateToTimestamp(LocalDateTime localDateTime) {
        return localDateTime.toInstant(TimeUtils.zoneOffset).toEpochMilli();
    }

    public static String dateToCusTom(LocalDateTime localDateTime, DateTimeFormatter formatter) {
        return localDateTime.format(formatter);
    }
}
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
Last Updated: 6/1/2024, 6:36:28 AM