package test;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.junit.Test;
public class TestDate {
@Test
public void test() throws Exception {
String launchTime = "2016-04-20 16:48";
//需要注意的是时间的设置, yyyy-MM-dd HH:mm:ss, 其中MM必须为大写, 才可以正确转为指定的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(sdf.parse(launchTime));
System.out.println(getTimeByMinute(1, sdf.parse(launchTime)));
}
public static String getTimeByMinute(int minute, Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);//设置时间, 若不设置则默认表示为获取当前时间
calendar.add(Calendar.MINUTE, minute);
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
}
}