N
N
Nikita Dergachov2017-02-10 23:36:23
Java
Nikita Dergachov, 2017-02-10 23:36:23

How to get current date and next day's date?

You need to get the current date in the format "February 10". And how to implement getting the next day and the previous one?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Malyarov, 2017-02-10
@Konstantin18ko

The current date

import java.util.Calendar;

 int Date;
 int Month;
 int Year;

public static void main(String args[]) {

Calendar calendar = Calendar.getInstance();

Date = calendar.get(Calendar.DAY_OF_MONTH);
Month = calendar.get(Calendar.MONTH);
Year = calendar.get(Calendar.YEAR);
  }

How to add a day
String dt = "2008-01-01";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  // dt is now the new date

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question