I want to mock a date object in Jun 1, 2024, 8:07:29.920 PM format in java 11.
Can anyone please help here.
I tried using the code below:
Date currentDate = new Date();
OffsetDateTime odt = OffsetDateTime.ofInstant(Instant.ofEpochMilli(currentDate.getTime()), ZoneId.of("UTC"));
ZonedDateTime zonedDateTime = ZonedDateTime.of(odt.getYear(), odt.getMonthValue(), odt.getDayOfMonth(), 6, 0, 0, 0, ZoneId.of("America/New_York"));
Date startDate = Date.from(zonedDateTime.toInstant());
Mockito.when(mockPriceMap.get("startDate")).thenReturn(startDate);
But this is generating date in this format: Tue Aug 06 15:30:00 IST 2024
whereas my requirement is in this format: Jun 1, 2024, 8:07:29.920 PM
New contributor
Neha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.