Reputation: 1
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 {
Upvotes: -1
Views: 3934
Reputation: 16419
You can get the current date and time from ZonedDateTime
:
ZonedDateTime now = ZonedDateTime.now();
And then you can format the time using DateTimeFormatter
's ISO_LOCAL_DATE
and ISO_LOCAL_TIME
:
String currentDateTime = DateTimeFormatter.ISO_LOCAL_DATE.format(now) +
DateTimeFormatter.ISO_LOCAL_TIME.format(now);
Which produces "2022-03-14 12:40:32.8071372"
.
Upvotes: 0