0

For example if DateTime is :

DateTime dt= Datetime.newInstance(2020,07,12,18,30,0); //using System.now() for dt
DateTime.newInstanceGmt(dt.date().addDays(-5),Time.newInstance(00,00,01,00)) ;// should give 2020-07-07 00:00:01 but gives 2020-07-08 00:00:01

It gives 2020-07-07 00:00:01 in workbench, but not in apex.I am using System.now() for DateTime dt in apex , but even though If I print dt in email body,It gives me value in gmt , but for processing, it is considering current user's time zone.

Is this the behavior? Can anybody please confirm?

Thanks in advance!!

  • 1
    what is your locale and timezone setting on user record? – sanket kumar Jul 13 at 8:03
  • @sanketkumar The time zone is (GMT+05:30) India Standard Time (Asia/Kolkata) and Locale is English (India). – Isha Arora Jul 13 at 12:07
  • Can you clarify "DateTime dt= 2020-07-12 18:30:00". That's not valid apex. How is dt getting set? Is that time GMT or local? – Jason Clark Jul 13 at 14:09
  • @JasonClark We are using System.now for setting DateTime i.e. dt, I have edited the question for more clarity. – Isha Arora Jul 14 at 5:04
  • @JasonClark The question here is according to the documentation System.now() gives time in GMT which is what I get when I print it, but when I am processing it as in performing some actions on it like addDays(), it is giving result in accordance with current user's time zone rather than GMT timezone – Isha Arora Jul 14 at 5:13

Your Answer

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

Browse other questions tagged or ask your own question.