public static SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");//这个可以自己定义
/**
* yyyy-mm-dd
* @param num
* @return
*/
public static String format_today()
{
Calendar c = Calendar.getInstance();
return s.format(c.getTime());
}
/**
* yyyymmdd
* @return
*/
public static String format_today_2()
{
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
Calendar c = Calendar.getInstance();
return sim.format(c.getTime());
}
/**
* yyyy-mm-dd
* @param year_num
* @return
*/
public static String format_year_today(int year_num)
{
Calendar c = Calendar.getInstance();
c.add(Calendar.YEAR,year_num);
return s.format(c.getTime());
}
public static String format_year_today_2(int year_num)
{
SimpleDateFormat sim = new SimpleDateFormat("yyyyMMdd");
Calendar c = Calendar.getInstance();
c.add(Calendar.YEAR,year_num);
return sim.format(c.getTime());
}
/**
* yyyy-mm-dd
* @param month_num
* @return
*/
public static String format_month_today(int month_num)
{
Calendar c = Calendar.getInstance();
c.add(Calendar.MONTH,month_num);
return s.format(c.getTime());
}
/**
* yyyy-mm-dd
* @param date_num
* @return
*/
public static String format_date_today(int date_num)
{
Calendar c = Calendar.getInstance();
c.add(Calendar.DATE,date_num);
return s.format(c.getTime());
}
/**
* yyyy-mm-dd
* @param year_num
* @param month_num
* @param date_num
* @return
*/
public static String format_all_today(int year_num,int month_num,int date_num)
{
Calendar c = Calendar.getInstance();
c.add(Calendar.YEAR,year_num);
c.add(Calendar.MONTH,month_num);
c.add(Calendar.DATE,date_num);
return s.format(c.getTime());
}
关于java日期的函数
最新推荐文章于 2022-02-25 20:00:37 发布