본문 바로가기

Java

string date 계산

String now = "20190823 10:20:10";
String min = "15";
String sec = "55";
System.out.println(getDate(now, min, sec));

public static String getDate(String now, String min, String sec) {
	SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
	try {
		Date nowDate = sdf.parse(now);
		long nowMilliSeconds = nowDate.getTime();
		nowMilliSeconds += Integer.parseInt(min) * 60 * 1000;
        nowMilliSeconds += Integer.parseInt(sec) * 1000;
		return sdf.format(nowMilliSeconds);
	} catch (ParseException e) {
		e.printStackTrace();
	}
	return null;
}