I probably saw this question 100 times, but still don't understand. So basically I want to display only the Time from a datetime field but not the Date. However I always get the GMT time. I know I could create a wrapper and format my datetimes in the controller. But why should I create a wrapper class only to display datetimes. I made some tests and here is what I got :

//not good, display GMT time
<apex:outputText value="{0,date,HH:mm}">
     <apex:param value="{!item.Inspection_Date_Time__c}" name="p1" />

//not good, display GMT time
<apex:outputText value="{0,number,00}:{1,number,00}">
    <apex:param value="{!item.Inspection_Date_Time__c.time.hours}" name="p1" />
    <apex:param value="{!item.Inspection_Date_Time__c.time.minutes}" name="p2" />

//time is correct but I want only the time not the date
<apex:outputText value="* {!item.Inspection_Date_Time__c}" />

//display GMT time, and what's the difference with the previous line ?
<apex:outputText value="{!item.Inspection_Date_Time__c}" />

//time is correct but I want only the time not the date
<apex:outputField value="{!item.Inspection_Date_Time__c}" />

Anyone found a solution for that(except via the controller)?




3 Answers 3


Use Apex to get User's TimeZone and offset time. e.g.

<apex:page controller="TimeZoneController">
    <apex:outputText value="{0,date,dd/MM/yyyy HH:mm:ss}">
        <apex:param value="{!NOW()+offset}"/>

public class TimeZoneController{
    public Double offset{get{
        TimeZone tz = UserInfo.getTimeZone();
        //Milliseconds to Day
        return tz.getOffset(DateTime.now()) / (1000 * 3600 * 24.0);
    public TimeZoneController(){

[Reference] https://www.xgeek.net/salesforce/display-datetime-with-timezone-in-visualforce-page/

  • Wow, your solution is awesome!
    – manza
    Nov 24, 2015 at 6:56
  • I do not think this accounts for Daylight Savings Time. The offset would need to be calculated on an item by item basis. E.g. Created Date could be in Daylight Time, and Last Modifed could be in Standard TIme. Hence using the same offset would be incorrect. But only out by an hour for some scenarios. Oct 10, 2017 at 10:28

I faced same issue again and again. It shows the GMT time. I created a Map of Map and then Show it on visualforce page. It is working fine

Map<item,String> timeMap = new Map<Item,String>();
for(Item i : itemList){
String t = String.valueof(i.TIMEFIELD)

On Visualforce page you can show it like:

  • Creating a Map is much the same as creating a wrapper. So it is implied that a map is not wanted (by OP) Solution not via controller. Oct 10, 2017 at 10:30


You can try this crazy solution. Just use javascript to get the time:

            var currentText = jQuery(this).text();
            jQuery(this).text( currentText.substring(currentText.lastIndexOf(' '), currentText.length) );

<apex:outputPanel styleClass="timeValue">
    <apex:outputField value="{!testacc.createdDate}"  />

Well, the apex and Datetime object are your friends!

hour: Returns the hour component of a Datetime in the local time zone of the context user
minute: Returns the minute component of a Datetime in the local time zone of the context user

(From here: Datetime Methods)

So why can't you just create a time you want from a goven Datetime?

Controller: public String timeOk { get; set; } public Account testacc { get; set; }

testacc = [select createdDate from account limit 1];
timeOk = testacc.createdDate.hour() + ':' + testacc.createdDate.minute();


<apex:outputText value="{!timeOk}" />
  • It's for a list of records, and I know how to do it via a controller. I just don't want to create a wrapper class only to display a list of records, and why salesforce doesn't support a thing so simple ?! But thanks
    – brovasi
    Aug 27, 2013 at 8:29
  • Try javascript? ;) Updated my answer. Aug 27, 2013 at 9:05
  • Haha yeah with Javascript of course, I prefer the wrapper class then lol ;-). But isn't it crazy there is nothing for Visualforce ?!
    – brovasi
    Aug 27, 2013 at 9:15
  • Yeah, Visualforce is not yet perfect :() Aug 27, 2013 at 9:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .