Java:如何在我的Time中添加10分钟 [英] Java : how to add 10 mins in my Time
本文介绍了Java:如何在我的Time中添加10分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在这个时间
String myTime = "14:10";
现在我想添加10分钟,这样就可以 14:20
Now I want to add like 10 mins to this time, so that it would be 14:20
这可能,如果可行,怎么办?
Is this possible, and if so, how?
谢谢
推荐答案
这样的事情
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.
这篇关于Java:如何在我的Time中添加10分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文