考慮此程序:合併日期和時間到時間戳
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
public class Program {
public static void main(String[] args) throws Exception {
Date d = new Date(System.currentTimeMillis());
Time t = new Time(System.currentTimeMillis());
System.out.println("d = " + d);
System.out.println("t = " + t);
Timestamp ti = new Timestamp(d.getTime() + t.getTime()); // not working
System.out.println("ti = " + ti);
}
}
我有變量D代表日期和T的時候,我怎麼能由這兩個變量建立時間戳?
你的時間't'應該有它的日期設置爲1/1/1970和你的日期'd'應該有它的時間設置爲00:00:00 ... – assylias 2014-10-30 09:42:14