如何创建日期为23/09/2007的时间戳?
发布于 2009-06-10 11:19:55
说到Timestamp
,我猜你指的是java.sql.Timestamp
。您会注意到这个类有一个接受long
参数的构造函数。您可以使用DateFormat
类对其进行解析:
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = dateFormat.parse("23/09/2007");
long time = date.getTime();
new Timestamp(time);
发布于 2009-06-10 11:38:27
那这个呢?
java.sql.Timestamp timestamp = java.sql.Timestamp.valueOf("2007-09-23 10:10:10.0");
发布于 2009-06-10 11:26:31
你说时间戳是什么意思?如果您指的是从Unix时代开始的毫秒数:
GregorianCalendar cal = new GregorianCalendar(2007, 9 - 1, 23);
long millis = cal.getTimeInMillis();
如果您想要一个实际的java.sql.Timestamp对象:
Timestamp ts = new Timestamp(millis);
https://stackoverflow.com/questions/974973
复制相似问题