function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion 

Date Time Issue--URGENT---

Hi ,the below actually converts the time from different time zones to pst time zone and save datetime repectively so the pst users always see date time field in their time zone only


Date objDate = System.Today().toStartOfWeek().addDays(6);        
        DateTime customerDateTimeString = Datetime.newInstanceGMT(objDate.year(), objDate.month(),, 2, 0, 0);
        DateTime customerDateTime = customerDateTimeString ;
        string customerTimeZoneSidId = 'America/Los_Angeles';
        TimeZone customerTimeZone = TimeZone.getTimeZone(customerTimeZoneSidId);
        ///calculates difference between time zones
        integer offsetToCustomersTimeZone = customerTimeZone.getOffset(customerDateTime);
        TimeZone tz = UserInfo.getTimeZone();
        integer offsetToUserTimeZone = tz.getOffset(customerDateTime);
        integer correction = offsetToUserTimeZone - offsetToCustomersTimeZone;
        DateTime correctedDateTime = customerDateTime.addMinutes(correction / (1000 * 60));              
            saturdayDateTime  = correctedDateTime;   
            saturdayDateTime  = Datetime.newInstance(objDate.year(), objDate.month(),, 2, 0, 0);




but problem is it works fine in my developer account but not in some other sandbox account ..

i have the same TimeZone and Locale i have crosschecked ....(ANy help on this , what else can i check )

Problem it it storing the same date a day ahead for all other uers and therefore showing one day ahead for pst users also..