[SalesForce] Change TimeZone of CreatedDate

I am having some trouble finding detailed information on the 'z' value in the <apex:outputText value="{0,time, hh:mm a z}">

I have to display the timezone as PST and the z is only displaying GMT

I typically just use an apex method to change the format of the timezone but can't do that this time for a couple of reasons. (I can add these reasons in if you feel necessary). So what I am looking for is a way to manipulate the <apex:outputText> tag. Is this possible without apex? I imagine it is something along the lines of:

        <apex:repeat value="{!keysComment}" var="key">
            <th colspan="5" id="casenumber">{!key}</th>
            <apex:repeat value="{!dateHeaderComments[key]}" var="td">
                <tr>
                    <td>
                        <apex:outputText value="{0,time, hh:mm a z, 'America/Los_Angeles'}">
                            <apex:param value="{!td.commentData.CreatedDate}" />
                        </apex:outputText>
                    </td>
                </tr>
            </apex:repeat>
        </apex:repeat>

Resources that were semi helpful:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_timezone.htm#apex_methods_system_timezone

https://paulforce.wordpress.com/2009/08/27/formatting-time-in-apex/

Best Answer

This is a slightly hacky way of going about it but this article worked for me: http://www.ultrageek.com/?p=169

I was able to offset the timezone by how ever many hours different I am from GMT time. So my outputText tag looks like:

<apex:outputText value="{0,time, hh:mm a}">
    <apex:param value="{!td.commentData.CreatedDate -7/24}" />
</apex:outputText>

This enables me to change the timezone without having to convert the DateTime into a string.

According to the documentation you get the -0.29 value by taking your GMT date/time field and divide one(1) by the number of hours offset. 1/4 = .166~ and 1/5 = .2 respectfully. This is obviously incorrect (the time difference between GMT and PST is 7 hours and 1/7 != 0.29) but what you can do is take the time difference and divide it by 24. ie: -7/24.

Related Topic