1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| package com.date.test;
import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List;
@SpringBootTest public class test {
@Test public void getDate() {
for (int x = 0; x < 7; x++) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + x); Date date = calendar.getTime();
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); String today = format.format(date);
System.out.println(today); } } }
|