I am creating a dataset in yml format to initialize a table in a postgresql database
- id : 5
description : "test5"
is_deleted : false
last_redaction_date : 2021-12-13 15:09:52.715570
persist_date : 2022-03-02 15:09:52.715570
title : "test5"
user_id : 15
How can I set the current date in the required format to the persist_date variable so as not to manually enter the date each time?
@AutoConfigureMockMvc
@SpringBootTest(classes = JmApplication.class)
public class TestQuestionResourceController extends AbstractClassForDRRiderMockMVCTests {
@Autowired
private MockMvc mvc;
@Test
@DataSet(cleanBefore = true,
value = {
"dataset/testQuestionResourceController/question_different_date.yml",
},
strategy = SeedStrategy.CLEAN_INSERT
)
public void getQuestionSortedByWeightForTheWeek() throws Exception {
You can get the current date and time from
ZonedDateTime
:And then you can format the time using
DateTimeFormatter
'sISO_LOCAL_DATE
andISO_LOCAL_TIME
:Which produces
"2022-03-14 12:40:32.8071372"
.