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
jkucera2jkucera2 

Date.valueOf() returns wrong timezone (bug)

There seems to be a bug in the date methods.  Steps to repro:

 

        Integer year=2012;    
        Integer month=12;
        Integer day=29;
        Integer hourInUTC=4;
        DateTime dt=dateTime.newInstanceGMT(year, month, day, hourInUTC,0,0);
        system.debug('dateTime is:'+dt.format());
        //Stupid function creates a date in GMT even though the DateTime value is clearly the previous day and doc clearly states that it should return the local time zone
        Date d=date.ValueOf(dt);
        system.debug('date is:'+d.format());

 Expected - the date is actually the 28th (9pm)

 

Actual - the date d is shown as the 29th.

 

Also, the dateTIme.now() doesn't return a GMT value, it returns the local timezone.  Either the documentation is wrong, or there's a bug in the method.

yvk431yvk431

Hi,

 

Try this one , actually this was also from the salesforce documentation

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_datetime.htm

 

Datetime GMTDate = Datetime.newInstanceGmt(2011,6,1,12,1,5);
String strConvertedDate = GMTDate.format('dd/MM/yyyy hh:mm:ss a', 'PST');

 

 

Thanks

jkucera2jkucera2

The doc states that valueOf() should return the local time zone, so if DateTime was initiatied in GMT then .valueOf() should return the local time zone.

 

Its a doc bug or a bug in valueOf().