可以使用SimpleDateFormat类来将时间戳转换为指定格式的时间字符串,并拼接上毫秒。

以下是一个示例代码:

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

public class Main {
    public static void main(String[] args) {
        long timestamp = System.currentTimeMillis(); // 获取当前时间戳
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); // 定义时间格式
        String timeWithMillis = sdf.format(new Date(timestamp)); // 将时间戳转换为时间字符串
        System.out.println(timeWithMillis); // 输出时间字符串
    }
}

输出结果类似于:2022-01-01 12:34:56.789

Java时间戳拼接毫秒

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

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