9/4/2014 3:55:10 AM
這裏是我當前的日期和時間,我想添加10小時讓我凸輪比賽與設備的當前時間,請告訴我,怎樣才能實現如何在Java中加入10小時當前日期和時間
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String currentDateandTime =" 9/4/2014 3:55:10 AM ";
Date date = formatter.parse(currentDateandTime);
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR, 10);
System.out.println("Time here "+calendar.getTime());
}
此代碼正在嘗試,但我不能穿上Impalement,請幫助我在哪裏做錯誤。
formatter = DateFormat.getInstance();我認爲你錯過了這條線 – 2014-09-04 11:31:25
使用compareto()方法來比較 – DJhon 2014-09-04 11:35:24
這不是一個正確的答案,但如果你定期處理日期,庫Joda-Time是必須的。 – 2014-09-04 11:56:16