如何增加我的(字符串)时间10分钟? [英] How to add 10 minutes to my (String) time?
本文介绍了如何增加我的(字符串)时间10分钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个时间:
String myTime = "14:10";
现在我想增加10分钟的时间,以使它成为 14:20
Now I want to add 10 minutes to this time, so that it would be 14:20
我该如何实现?
推荐答案
类似的东西
String myTime = "14:10";
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date d = df.parse(myTime);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.add(Calendar.MINUTE, 10);
String newTime = df.format(cal.getTime());
作为一个合理的警告,如果在这10分钟的时间内涉及夏令时,则可能会出现一些问题.
As a fair warning there might be some problems if daylight savings time is involved in this 10 minute period.
这篇关于如何增加我的(字符串)时间10分钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文