Java 时间戳 - 如何创建日期为 23/09/2007 的时间戳?

2022-01-13 00:00:00 datetime timestamp date java

如何创建日期为 23/09/2007 的时间戳?

How can I create a Timestamp with the date 23/09/2007?

推荐答案

通过 Timestamp,我想你的意思是 java.sql.Timestamp.你会注意到这个类有一个接受 long 参数的构造函数.您可以使用 DateFormat 类对其进行解析:

By Timestamp, I presume you mean java.sql.Timestamp. You will notice that this class has a constructor that accepts a long argument. You can parse this using the DateFormat class:

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
new Timestamp(time);

相关文章