0

I've a custom Date&Time field on Opportunity.When I retrieve for a single record,this date value is showing correct in Developer console but Salesforce UI is showing wrong date.I'm in EST Time-zone.Please help me on this.

1 Answer 1

1

What is happening is that the UI is not formatting the date for your current Time Zone.

If you're not displaying the date then the date will show in GMT.

I can recommend a quick way to fix this

Create a component:

<apex:component access="global" controller="FormattedDateTimeController">{!FormattedDatetime}
    <apex:attribute assignTo="{!valueToFormat}" description="The DateTime value to be rendered" name="datetimeValue" type="DateTime"></apex:attribute>
    <apex:attribute assignTo="{!definedFormat}" description="The optional format to use for the DateTime value to be rendered" name="datetimeFormat" type="String"></apex:attribute>
</apex:component>

Controller:

public class FormattedDateTimeController {
    public DateTime valueToFormat { get; set; } //property that reads the datetime value from component attribute tag
    public String definedFormat { get; set;} //property that reads the string value from component attribute tag

    public String getFormattedDatetime() {
        if (valueToFormat == null) {
                return ''; 
        } else { 
            if (definedFormat == null) {
                return valueToFormat.format(); //return the full date/time in user's locale and time zone
            } else { 
                return valueToFormat.format(definedFormat);  //Specify Time zone like IST,CST
            }
        }
    }
}

and use it on a page like so:

<c:FormattedDateTime datetimeValue="{!pr.runDate}" datetimeFormat="MM/dd/yyyy" />
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.