October 14, 2013

How to convert time zone in Salesforce?

format(String, String) is used to change the time zone.

Sample Code:

Visualforce page:

<apex:page controller="Sample">
Current Date in US : {!USDateTime}


Current Date in UK : {!UKDateTime}

Apex Controller:

public class Sample { 
    public String USDateTime {get;set;}
    public String UKDateTime {get;set;}    
    public Sample() {
        DateTime temp = System.now();
        USDateTime = temp.format('MM/dd/yyyy HH:mm:ss', 'America/New_York');
        UKDateTime = temp.format('MM/dd/yyyy HH:mm:ss', 'London');        



1 comment: