Here you can find the source of addDaysByFormatter(int days, String dateFormat)
Parameter | Description |
---|---|
days | days after or before current date, use + and - to add. |
dateFormat | the formatter of date, such as:yyyy-MM-dd HH:mm:ss:SSS. |
public static String addDaysByFormatter(int days, String dateFormat)
//package com.java2s; //License from project: Apache License import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class Main { /**// ww w . j av a 2 s .c o m * get specified time string in specified date format. * * @param days * days after or before current date, use + and - to add. * @param dateFormat * the formatter of date, such as:yyyy-MM-dd HH:mm:ss:SSS. */ public static String addDaysByFormatter(int days, String dateFormat) { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.DATE, days); SimpleDateFormat formatter = new SimpleDateFormat(dateFormat); return formatter.format(cal.getTime()); } public static String getTime() { SimpleDateFormat sdf = new SimpleDateFormat("HHmmssSSS"); return sdf.format(new Date()); } }