
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateFunctions
{
public String today_String_date ()
{
Date date = new Date();
SimpleDateFormat sdf=new SimpleDateFormat("ddMMyyyy_HHmmss");
String ds=sdf.format(date);
return ds;
}
public boolean isValidDate(String inDate,String FORMAT)
{
SimpleDateFormat dateFormat = new SimpleDateFormat(FORMAT);
dateFormat.setLenient(false);
try {
dateFormat.parse(inDate.trim());
} catch (Exception pe) {
return false;
}
return true;
}
public String today_date_with_format (String format)
{
/// ddMMyyyy_HHmmss
Date date = new Date();
SimpleDateFormat sdf=new SimpleDateFormat(format);
String ds=sdf.format(date);
return ds;
}
public String ChangeDateFormat(String OLD_FORMAT , String NEW_FORMAT ,String oldDateString) throws Exception
{
//09/11/2017
//OLD_FORMAT = "MM/dd/yyyy";
//11-Sep-2017
//NEW_FORMAT = "dd-MMM-yyyy";
// August 12, 2010
//String oldDateString = "12/08/2010";
String newDateString;
SimpleDateFormat sdf = new SimpleDateFormat(OLD_FORMAT);
Date d = sdf.parse(oldDateString);
sdf.applyPattern(NEW_FORMAT);
newDateString = sdf.format(d);
return newDateString.toString();
}
///Dates
public String curentDate ()
{
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format(new Date());
return date;
}
}
public String Get_Future_Past_Date(int Future_Past,String FORMAT) throws Exception
{
// past -xx
// Future +xx
// Today 0
//String FORMAT = "dd-MMM-yyyy";
String newDateString;
DateFormat dateFormat = new SimpleDateFormat(FORMAT);
Date myDate = new Date(System.currentTimeMillis());
Date oneDayBefore =new Date(myDate.getTime()+ Future_Past);
newDateString = dateFormat.format(oneDayBefore);
return newDateString.toString();
}