拜托,我怎么能:
因此,如果时间目前为13:20:31,则显示的时间为15:41:53 ...
答案 0 :(得分:0)
你可能会想要添加Calendar
这样的东西。例如:
Calendar future = Calendar.getInstance();
future.add(Calendar.HOUR_OF_DAY, enteredHour);
future.add(Calendar.MINUTE, enteredMinute);
future.add(Calendar.SECOND, enteredSecond);
//And so on...
//Now the calendar instance 'future' holds the current time plus the added values.
至于输入时间,一种可能性是将其作为文本输入,然后使用DateFormatter
从中获取Date
。例如:
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
Date enteredDate = sdf.parse(string); //String can be the input from an edit-text for example.
//You can now get the hours/minutes/seconds from the date with any of the Dates get-methods.
答案 1 :(得分:0)
/**
* This function returns the formatted string of current time, shifted by time interval, </br>
* set in "shift" parameter, formatted in the same way.
* @param shift
* @return
* @throws ParseException
*/
static String addToCurrent(String shift) throws ParseException {
long now=System.currentTimeMillis();
SimpleDateFormat df = new SimpleDateFormat("HH:mm:ss");
Date shiftDate=df.parse(shift);
long shiftedLong= shiftDate.getTime()+now;
return df.format(shiftedLong);
}