import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void main(String[] args) throws ParseException { // 有一个时间2021年08月06日,往后2天 16小时49分06秒后的时间是多少。 // 把字符串时间拿到程序中来 String dateStr="2021年08月06日"; //把字符串解析成为日期对象(必须与被解析时间的形式完全一样) SimpleDateFormat date=new SimpleDateFormat("yyyy年MM月dd日"); Date b=date.parse(dateStr); //往后2天 16小时49分06秒 long time=b.getTime()+(2L*24*60*60+16*60*60+49*60+6)*1000;//转换为毫秒 //格式化这个毫秒时间 System.out.println(date.format(time)); } }