-6

I have an app in which I need to get the year, month and the day seperate from the next day as an String. Can I do tis somehow with

SimpleDateFormat day = new SimpleDateFormat("dd");  
String Day = day.format(new Date()+1);  

or how can I get those? Please help me I'm a total beginner.

  • Thanks for participating in StackOverflow. As a total beginner, first three lessons: [1] Read the doc -- the [Java class doc](http://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html) and the [Oracle Tutorial](http://docs.oracle.com/javase/tutorial/datetime/TOC.html). [2] Search Google to further educate yourself on a topic. [3] [Search StackOverflow](http://stackoverflow.com/search?q=java+date+tomorrow) before posting. Your question has been addressed many times before. – Basil Bourque Aug 15 '15 at 03:15
  • Also duplicate of [Format date in java](http://stackoverflow.com/q/4772425/642706), and [Convert java.util.Date to String](http://stackoverflow.com/q/5683728/642706), and many others. – Basil Bourque Aug 15 '15 at 03:21

2 Answers2

6
SimpleDateFormat sdFormat = new SimpleDateFormat("dd");
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DATE, 1);
String day = sdFormat.format( calendar.getTime() )
Zyn
  • 614
  • 3
  • 10
0

Newer answer for Java 8 using time API.

LocalDate tomorrow = LocalDate.now().plusDays(1);
int year = tomorrow.getYear();
String month = tomorrow.getMonth().toString();
int dayOfMonth = tomorrow.getDayOfMonth();
Andrew Mairose
  • 10,615
  • 12
  • 60
  • 102