2013-07-04 60 views
0

我想在gmt時間內添加分鐘數。在Gmt + 530分鐘內添加分鐘

我通過使用此方法獲得gmt時間。

new Date().toGMTString(); 

如何在最終結果日期將這個結果轉化爲分鐘?

如何添加分鐘?

感謝

+0

http://joda-time.sourceforge.net/ – devnull

+0

[避免儘可能在Android中使用'Date'。(HTTP: *(聲明:鏈接到我自己的網站。)*由於@苛刻的答案建議,使用'日曆'。 – Eric

回答

1

一種方法是使用Calendar

public Date addMinute(Date date, int minuteToAdd) { 
     Calendar cal = Calendar.getInstance(); 
     cal.setTime(date); 
     cal.add(Calendar.MINUTE, minuteToAdd); 
      return cal.getTime(); 
} 
+0

2013年7月4日07:11:10 GMT如何將此字符串轉換爲日期格式? – dev

0

您可以先加分鐘,之後得到GMT串

Calendar calendar = Calendar.getInstance(); 

// add the minutes 
calendar.add(Calendar.MINUTE, 12); 

// now obtain the date 
Date date = calendar.getTime(); 

System.out.println(date.toGMTString()); 

當心,因爲toGMTString()已被棄用。考慮使用SimpleDateFormat代替

0

你可以做這樣的事情:

Date temp = new Date().toGMTString(); 
Date newDate=new Date(temp + (530 * 60000));