Is there a reason that the below returns 2017-11-30? I know changing it to Datetime.newInstance fixes it, but I'm mostly wondering why this happens.
Datetime myDate = Date.newInstance(2017, 12, 1); system.debug(myDate.format('yyyy-MM-dd'));
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
when you create the date via Date.newInstance it is creating the 1st of dec as per GMT.
Once you call format on it. It applies your locale settings which would not be as GMT and your timezone might be behind GMT by few hours. So it is showing you 30th Nov.
E.g. If you add few hours to it then it will start showing the date you expected. The hours that you might to add is based on what is the offset of your timezone with the GMT.