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.
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.