I am new to Apex.

I have instantiated the Datetime field with (2019, 12, 31, 12, 12, 12) where hour/minute/sec all are '12'. but in the output it is returning '20:12:12'.

Please help me to understand the cause. Screenshot attached.

enter image description here


You are witnessing the automating conversion of a GMT time (the numbers you passed in to DateTime.newInstance) to your local timezone. The mechanism helps when orgs have users working in multiple timezones

See the various Datetime Class methods that output with and without this conversion.

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.