Convert Date Time Zone To Another Time Zone In Apex

Sample Code:

//Get current date time in GMT format
Datetime dt =;

//Convert it into Pacific Standard Time(PST).
String dtPST = dt.format('yyyy-MM-dd HH:mm:ss', 'PST');

System.debug('dt-' + dt);
System.debug('dtPST-' + dtPST);

  • Darshan Gandhi

    I want to convert to a specific 8:00 AM CST for any sales force users no matter in what timezone he is. I am using lighting input and type as date time in my form so at the end I want Date Time returned from the apex instead of string.