I have converted a Date into DateTime format, and it is returning me the hour format in 00:00:00 but I want it to be in 23:59:59
Date startDate = Date.newInstance(2021,2,1);
This returns the output as 2021-02-01 00:00:00
When I try to convert this to the 23:59:59 hour format by using the below code
DateTime startDateConvertTwo = DateTime.newInstance(startDate, Time.newInstance(23, 59, 59, 0));
It is pushing the date to next day and returning the value of 2021-02-02 07:59:59
I tried to sort this out by changing the values of Time.newInstance by adding it as Time.newInstance(15, 59, 59, 0) by doing which I get the expected result. But is it the right way to achieve what I am trying to do?
Please let me know if there are any other ways.