-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
  • 63
  • 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
  • 13,325
  • 3
  • 51
  • 57
0

You can use below

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

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

int day = LocalDate.getDayOfYear();

Michael Grinnell
  • 922
  • 1
  • 12
  • 32
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,713
  • 1
  • 16
  • 33