+ Start a Discussion

DateTime in User's Timezone directly from SOQL

Hi All,

I've a SOQL query which gives me the CompletedDate and CreatedDate in GMT.

Is it possible to get the same in my time zone. (KST)


List<AsyncApexJob> batchJob = [SELECT CreatedDate, JobItemsProcessed, Status, ExtendedStatus, NumberOfErrors, CompletedDate, JobType, TotalJobItems, ApexClassId FROM AsyncApexJob where id = : batchProcessId ];


When i added a line as below i got in KST.

kstCreatedDateMod = String.valueOf(aaj.CreatedDate);


But is it posssible to get directly from query? without any additional lines of code.



Thanks in Advance,

Rohit R

Jia HuJia Hu
You can try this way,

user a = [select id, createddate from user limit 1];
system.debug( a.createddate.format('MM/dd/yyyy hh:mm a', 'KST') );