Java – how to add an hour to my time
•
Java
I have time in the following format and use this value to set the text of my button
String strDateFormat = "HH:mm: a"; SimpleDateFormat sdf ; sdf = new SimpleDateFormat(strDateFormat); startTime_time_button.setText(sdf.format(date));
Now my question is, can I add one hour to this time format?
Solution
I think the best and easiest way is to use Apache commons Lang:
Date incrementedDate = DateUtils.addHour(startDate,1);
http://commons.apache.org/lang/api-2.6/org/apache/commons/lang/time/DateUtils.html
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码