读书人

Java中日期种编程题

发布时间: 2013-04-12 18:33:12 作者: rapoo

Java中日期类编程题

前言:这里整理一些关于时间方面的面试编程题


问题:取得当前时间的年月日,小时分秒。

方案:

/** *计算两个时间段相距天数 * @authorLiangGzone * @version2013.04.10 */public class TwoDate {  publicstatic void main(String[] args) throws Exception {  StringoldStr = "2000-9-9";  StringnewStr = "2000-8-8";  longoldLong = 0;  longnewLong = 0;  DateFormatdateFormat = DateFormat.getDateInstance();  oldLong= dateFormat.parse(oldStr).getTime();  newLong= dateFormat.parse(newStr).getTime();  longresult = Math.abs(oldLong-newLong);  System.out.println(result/24/60/60/1000);  }}




读书人网 >编程

热点推荐