1

When getting events that are not marked all day, they have their properly timezoned start and end times, so turning them into a datetime object is no problem.

When an event is marked all day, their start and end times are just 'dates', so they get set to midnight automatically. However, when you attempt to turn these into datetimes, the timezone gets applied, so for me, being in GMT-6, if I pull an all day event for April 4th, its start time turns into: 04/04/2018T00:00:000Z.

But then turning this into a date in JavaScript on my client side now turns into April 3rd at 7pm as it subtracts six hours for the timezone. If an event is not marked all day, then for me, it will correctly be six hours ahead, so when I turn it into a date in JavaScript, all is fine.

Is there a clean way to deal with these all day events and timezones?

  • Can you provide some of your code? – gNerb Apr 2 '18 at 16:16
  • There isn't really code needed here. I take ev.StartDateTime (where ev is an event I queried), and if it is all day, it will be something like this: 04/04/2018T00:00:000Z. Then in my javascript if I do new Date(thatTime), it applies the timezone and now it is 04/03/2018 7:00pm for GMT-5. Non all day events are fine because they were set with a proper datetime, but all day events just get set with a date, that converts to a datetime at midnight – Tyler Dahle Apr 2 '18 at 16:22
0

Try to use format() method for the times, so that it'll convert the stored date in your locale.

For handling all IsAllDayEvent field of event object. Link

  • Format is fine for displaying the correct time in apex, but I want to pass the correct datetime as a string to Javascript, so I can pass that into new Date() – Tyler Dahle Apr 2 '18 at 16:24
  • One thing you can try. Extract the day, month, year with Date/DateTime class functions, and pass those and build date in respective function. This might not be best solution, however this will work. – Ysr Shk Apr 2 '18 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.