0

I have an object of type Time startWorkingTime and object of type DateTime nextBusinessDay. I want to create new object of type DateTime based on startWorkingTime and nextBusinessDay.
Here is my code:

DateTime startWorkingTime = DateTime.newInstance(nextBusinessDay.year(), nextBusinessDay.month(), nextBusinessDay.day(), currentStartHours.hour(), currentStartHours.minute(), currentStartHours.second());

After startworkingtime the time is set one hour earlier

For example in bold:

23:59:24:025 USER_DEBUG [188]|DEBUG|currentStartHours 09:00:00.000Z
23:59:24:025 USER_DEBUG [189]|DEBUG|currentStartHours.hour() 9
23:59:24:025 USER_DEBUG [197]|DEBUG|startWorkingTime 2017-08-04 08:00:00

Could you please explain why the hour in startWorkingTime is 08:00:00 and advise how to fix it?

2
  • 2
    What's your time zone? Did you try Datetime.newInstanceGmt?
    – Adrian Larson
    Aug 3, 2017 at 21:14
  • Thank you Adrian. Datetime.newInstanceGmt helped me solve the problem.
    – sfdev
    Aug 3, 2017 at 21:24

1 Answer 1

1

Use Datetime.newInstanceGmt instead.

Datetime instance = Datetime.newInstanceGmt(year, month, day, hour, minute, second);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .