0

In my model I have the following:

private Date exampleDate;

public Testing(Date exampleDate) {
        this.exampleDate = exampleDate;
    }

public Date getExampleDate() {
        return (Date) this.exampleDate.clone();
    }

    public void setExampleDate(Date exampleDate) {
        this.exampleDate = (Date) exampleDate.clone();
    }

And I am trying to output an array of objects as follows

@RestController
public class TestingController {
    @GetMapping("/saved")
    public List<Testing> getData() {
        List<Testing> savedDatas = new ArrayList<>(Arrays.asList(
                new Testing(
                        1,
                        "Text",
                        2000-1- 1),
                new Testing(
                        2,
                        "Text2",
                        new Date(27 / 03 / 19)),

I tried to use new Date but that doesn't work, so what exactly do I need to pass as the third argument as type Date instead of String or int?!?!

helpmepie
  • 244
  • 1
  • 6
  • 19

1 Answers1

1

I would suggest you use the newer classes:

LocalDateTime

and

ZonedDateTime

Then you can get a LocalDateTime instance by using the static factory methods:

LocalDateTime.of(date, time); //or
LocalDate.of(date);
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ivan Dimitrov
  • 332
  • 1
  • 10