2

So I have a visualforce page displaying a query. But when it is being display on a force.com sites page. The created dates are different.

Visualforce page inside sandbox: enter image description here

Visualforce page on force.com sites: enter image description here

Here's the query to get the items

purchaseRequest = [select id, name, CreatedBy.Name, Selected_Request__c, Ownerid, CreatedDate
                            from Purchase_Request__c 
                            where Purchase_Request__c.CreatedDate = TODAY];

As you can see, line item PR-00000016 has a datetime 2/25/2014 8:07am for the visualforce page view inside the sandbox environment. Which is PST at time of creation. But the visualforce page that is being viewed through the force.com site public view is show a datetime 2/25/2014 4:07pm for PR-0000016.

My only conclusion is that the server that host the force.com site for me is in another country and is displaying the date in their time zone. Does anyone have any other idea?

I won't be able to use this to display for our customers if this is happening. Is there a way to set time zones for force.com sites?

2

Keep in mind, this could be timezone differences. Most likely when you are logged in, created date is converted to your current user's timezone, while in sites it's most likely GMT. Please add your timezone to your create date format and you'll be able to determine if this is the case.

<apex:outputText value="string: {0,date,yyyy.MM.dd 'at' HH:mm:ss z}"> 
    <apex:param value="{!account.CreatedDate}" /> 
</apex:outputText>

Link to your simple date format doc

  • you are correct. The force.com site is displaying in GMT. – Pracha Yang Feb 25 '14 at 17:42
1

Force.com Sites displays times in GMT format only. In order to make Site show as per required format, you will need to add hours and then display which will make Force.com Site show correct time.

For eg: the PR-00000016 has a datetime 2/25/2014 8:07am PST and Force.com Site shows in GMT and you want to show in PST, then easy solution is to amend the difference hours and Site will show in desired date time.

Lets say the difference is of 12 hrs between GMT and PST, then use following code:

<apex:outputText value="string: {0,date,yyyy.MM.dd 'at' HH:mm:ss z}"> 
    <apex:param value="{!account.CreatedDate+1/2}" /> 
</apex:outputText>

Here 1/2 is half day, so if the difference is 4 hrs then it will be 1/6th of day.

Though not recommended solution, but above is simple workaround to get it working immediately.

  • You would have to change your code every 6 months if you are in a region affected by Daylight Savings as your time zone offset would change by one hour. – Colin Kenworthy Mar 22 '16 at 19:29
  • My thoughts are to make a workflow or trigger that populates a custom text field with the date and time you want to display for the CreatedDate. Assuming of course the record is created by a logged in user. Then use the text field in your VF page. – Colin Kenworthy Mar 22 '16 at 19:50

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.