[SalesForce] How to provide default DateTime value in UTC time

I am providing a default value to a DateTime field in my apex class.

customobject.DateTime__c = DateTime.parse('01/01/1990 12:00 AM');

I want to set the default value to 01/01/1990 12:00 am UTC time. Am i setting it properly.

My Salesforce organization timezone is set to Pacific. So when I go back and check the field in Salesforce, it is displayed as 01/01/1990 12:00 AM. I am trying to figure out, if it saved the datetime field to 01/01/1990 12:00 AM Pacific time or UTC?

Best Answer

DateTime.parse() uses the current user's locale and time zone. You can tell because when you view it in the UI, it has the same value you set. It's converted internally to UTC, but the value will not be 01/01/1990 12:00 am UTC because it's adjusted from your local Pacific time.

Instead, use DateTime.newInstanceGmt(year, month, date, hour, minute, second):

DateTime dt = DateTime.newInstanceGmt(1990, 1, 1, 0, 0, 0);