Java 13位时间戳转换为日期格式 - 代码示例
要将13位时间戳转换为日期格式,可以使用Java的'java.util.Date'类和'java.text.SimpleDateFormat'类。以下是一个示例代码:
import java.util.Date;
import java.text.SimpleDateFormat;
public class Main {
public static void main(String[] args) {
long timestamp = 1577836800000L; // 13位时间戳
Date date = new Date(timestamp);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String formattedDate = sdf.format(date);
System.out.println(formattedDate);
}
}
在上面的代码中,我们首先创建一个'Date'对象,将13位时间戳作为参数传递给它的构造函数。然后,我们创建一个'SimpleDateFormat'对象,并指定所需的日期格式。最后,我们使用'format()'方法将'Date'对象转换为指定格式的字符串,并将其打印出来。
在上面的示例中,我们将13位时间戳1577836800000转换为日期格式,并输出结果为'2020-01-01 00:00:00'。
原文地址: https://www.cveoy.top/t/topic/o8Bp 著作权归作者所有。请勿转载和采集!