+ Start a Discussion

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.




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



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





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().