I am trying to pass startDate's time as 00:00:00 and endDate's time as 23:59:59 but during debugging startDate's time is Thu Aug 09 10:30:00 IST 2018 and endDate's time is Tue Aug 14 10:29:59 IST 2018.Where am I doing wrong?
SimpleDateFormat estFormat=new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
estFormat.setTimeZone(TimeZone.getTimeZone("EST"));
Date startDate=estFormat.parse(sdate+" 00:00:00");
object.setStartDate(startDate);
Date endDate=estFormat.parse(edate+" 23:59:59");
object.setEndDate(endDate);
provided the sdate and edate are strings which have dates in MM/dd/yyyy format.
SOLUTION: USING JAVA-TIME API
sdate=sdate.trim()+" 00:00:00";
edate=edate.trim()+" 23:59:59";
DateTimeFormatter df = DateTimeFormatter.ofPattern("MM/dd/yyyy HH:mm:ss");
LocalDateTime localdatetime = LocalDateTime.parse(sdate,df);
Date startDate = Date.from(localdatetime.atZone(ZoneId.of("America/New_York" )).toInstant());
object.setStartDate(startDate);
localdatetime = LocalDateTime.parse(edate,df);
Date endDate = Date.from(localdatetime.atZone(ZoneId.of("America/New_York" )).toInstant());
object.setEndDate(endDate);