-1

Is there a way to get the date in java in days only? For instance Jan 1 would equal 1 and Feb 1 would equal 32? Instead of the standard time format yyyy/mm/dd? Perhaps by editing the date formater somehow:

DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.now();
Adam
  • 51
  • 8

4 Answers4

1

Use getDayOfYear():

LocalDate localDate = LocalDate.now();
System.out.println(localDate.getDayOfYear());

Returns: the day-of-year, from 1 to 365, or 366 in a leap year

Marvin
  • 12,215
  • 3
  • 50
  • 50
0

You can use below

Calendar calendar = Calendar.getInstance(); int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);

Nishesh Pratap Singh
  • 2,063
  • 2
  • 13
  • 20
0

int day = LocalDate.getDayOfYear();

Michael Grinnell
  • 872
  • 1
  • 11
  • 30
0

try this

SimpleDateFormat format1=new SimpleDateFormat("MM/dd/yyyy");
      Date dt1=format1.parse(pass your date);
      DateFormat format2=new SimpleDateFormat("EEEE"); 
      String finalDay=format2.format(dt1);
Vikram Saini
  • 2,478
  • 1
  • 15
  • 32