hi,
How to get next day in java?
Can some one please let me know?
Thanks
hi,
How to get next day in java?
Can some one please let me know?
Thanks
Try this code:
Code:import java.util.Calendar; public class Days { public static void main(String[] argv) { Calendar origDay = Calendar.getInstance(); System.out.println ("Original Date: " + origDay.getTime()); Calendar prevDay = (Calendar) origDay.clone(); prevDay.add (Calendar.DAY_OF_YEAR, -1); System.out.println ("Previous Day: " + prevDay.getTime()); Calendar nextDay = (Calendar) origDay.clone(); nextDay.add (Calendar.DAY_OF_YEAR, 1); System.out.println ("Next Day: " + nextDay.getTime()); } }
Use the class DateFormatSymbols in order to get the names of the days of the week.
The method getWeekdays() provide the string of days of week. To get the current day, use the Calendar class.
Code:Code:cal.get(Calendar.DAY_OF_WEEK)- This will return the current day. cal.get(Calendar.DAY_OF_WEEK)+1- This will return the next day.
Code:import java.util.Calendar; import java.text.*; public class GetNextDay { public static void main(String[] args) { String dayNames[] = new DateFormatSymbols().getWeekdays(); Calendar cal = Calendar.getInstance(); System.out.println("Today is " + dayNames[cal.get(Calendar.DAY_OF_WEEK)]); System.out.println("Tomorrow is a " + dayNames[cal.get(Calendar.DAY_OF_WEEK)+1]); } }
Thanks for the quick reply
I really needed the code for my friends website.
Bookmarks