import java.util.Date;
import java.text.SimpleDateFormat;
public class TimestampToFormattedTime {
public static void main(String[] args) {
// 定义时间戳
long timestamp = 1625241600000L;
// 创建一个SimpleDateFormat对象,指定日期格式
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// 使用Date构造函数将时间戳转换为Date对象
Date date = new Date(timestamp);
// 使用SimpleDateFormat的format()方法将Date对象格式化为字符串
String formattedTime = dateFormat.format(date);
// 打印格式化后的时间
System.out.println("Formatted Time: " + formattedTime);
}
}
用Java处理时间戳转化为格式化的时间
最新推荐文章于 2024-04-30 17:28:01 发布