2013-07-04 50 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));