-
懒羊羊
2024-04-12 d5d31b9096d6e50cdac2069426b19b4507a91237
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
package com.jcdm.main.plcserver.util;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
 
public class TimeUtil {
    public static String stringProcessing(String dateTimeStr){
        String result = "";
        // 找到 "javaDate=" 的位置
        int javaDateIndex = dateTimeStr.indexOf("javaDate=");
        if (javaDateIndex != -1) {
            // 从 "javaDate=" 后面开始截取
            javaDateIndex += "javaDate=".length();
 
            // 找到日期时间字符串结束的位置,这里假设是字符串的结尾或者空格的位置
            int endIndex = dateTimeStr.indexOf('}', javaDateIndex);
            if (endIndex == -1) {
                // 如果没有找到空格,就取到字符串的末尾
                endIndex = dateTimeStr.length();
            }
            // 使用 substring 方法截取日期时间部分
            String dateTimePart = dateTimeStr.substring(javaDateIndex, endIndex);
            result = dateTimePart;
        } else {
            System.out.println("javaDate= not found in the string.");
        }
        return result;
    }
 
    public static String getTimestamp(String param){
        String result = "";
        // 定义日期时间格式和时区
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8")); // CST通常表示中国标准时间,即东八区
 
        try {
            // 解析日期时间字符串
            Date date = sdf.parse("Mon Jan 01 17:05:23 CST 2024");
 
            // 获取时间戳(毫秒)
            long timestamp = date.getTime();
 
            // 输出13位时间戳
            result = String.valueOf(timestamp);
 
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
}