要将时间戳转换为指定格式的日期时间字符串,可以使用Java的SimpleDateFormat类。以下是一个示例代码:

import java.text.SimpleDateFormat;
import java.util.Date;

public class TimestampConverter {
    public static void main(String[] args) {
        long timestamp = 1690818327000L; // 时间戳,单位为毫秒

        // 创建SimpleDateFormat对象,指定输出格式
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

        // 将时间戳转换为Date对象
        Date date = new Date(timestamp);

        // 使用SimpleDateFormat对象格式化Date对象,得到指定格式的日期时间字符串
        String formattedDateTime = sdf.format(date);

        System.out.println(formattedDateTime);
    }
}

运行以上代码,将输出结果为:2023-08-29T16:05:27Z

java 将时间戳转换为 2023-08-29T160527Z

原文地址: https://www.cveoy.top/t/topic/iVNO 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录