package com.ruoyi.system.utils;

import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.TimeZone;

public class DateUtil {

    public static void main(String[] args) {
        System.out.println(new Date(1747636430331l));
        System.out.println(getCurDate());
        System.out.println(getShanghaiTimestamp());
        System.out.println(longToDateTimeString(1747636430331l));

    }
   public static String getCurDate() {
        return ZonedDateTime.now(ZoneId.of("Asia/Shanghai"))
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
    public static long getShanghaiTimestamp() {

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
        return new Date().getTime(); // 返回系统时间戳（需确保JVM时区正确）
    }

    public static String longToDateTimeString(long timestamp) {
        return Instant.ofEpochMilli(timestamp)
            .atZone(ZoneId.of("Asia/Shanghai"))  // 指定上海时区
            .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }
}
