首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

How to get tomorrow's date or future day

2012-12-24 
How to get tomorrows date or future day?I use the Calendar class to calculate with dates.eg:?class

How to get tomorrow's date or future day?

I use the Calendar class to calculate with dates.

eg:

?

class Main {     public static void main(String[] args) {        Date now = new Date();      Calendar cal = Calendar.getInstance();      cal.setTime(now);      cal.add(Calendar.DAY_OF_YEAR, 1);   }}
?

?

eg:

?

?

GregorianCalendar calendar = new GregorianCalendar();//Display the date now:Date now = calendar.getTime();DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, Locale.UK);String formattedDate = fmt.format(now);System.out.println(formattedDate);//Advance the calendar one day:calendar.add(calendar.DAY_OF_MONTH, 1);Date tomorrow = calendar.getTime();formattedDate = fmt.format(tomorrow);System.out.println(formattedDate);//Advance the calendar 30 more days:calendar.add(calendar.DAY_OF_MONTH, 30);Date futureDay = calendar.getTime();formattedDate = fmt.format(futureDay);System.out.println(formattedDate);
?

?

eg:

?

?

GregorianCalendar calendar = new GregorianCalendar();calendar.add(calendar.DAY_OF_MONTH, 0);System.out.println(new SimpleDateFormat("dd/MM/yyyy").format((Date) calendar.getTime()));
?

?

?

eg:

?

?

public String getDate(Integer getDay) {GregorianCalendar calendar = new GregorianCalendar();calendar.add(Calendar.DAY_OF_MONTH, getDay);return new SimpleDateFormat("dd/MM/yyyy")                           .format((Date)calendar.getTime());}
?

?

?

?

?

?

?

?

热点排行