Here you can find the source of addSecondCa(String d1, int timeSpan, String format)
public static String addSecondCa(String d1, int timeSpan, String format)
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Main { public static String addSecondCa(String d1, int timeSpan, String format) { Date d1Date = toDate(d1, format); long timeMili = d1Date.getTime() + timeSpan * 1000; d1Date.setTime(timeMili); return formatDateString(d1Date, format); }// ww w .j a v a2s. c o m public static Date toDate(String str) { if (null == str || str.trim().isEmpty()) { return null; } try { DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmt.parse(str); } catch (ParseException e) { return null; } } public static Date toDate(String dateString, String format) { try { DateFormat fmt = new SimpleDateFormat(format); return fmt.parse(dateString); } catch (ParseException e) { return null; } } public static long getTime(String s) { return parseMysql(s).getTime(); } public static String formatDateString(Date date, String format) { return new SimpleDateFormat(format).format(date); } public static Date parseMysql(String s) { try { DateFormat fmtTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return fmtTemp.parse(s); } catch (ParseException e) { return null; } } }