+ Start a Discussion
Jerun JoseJerun Jose 

apex:outputtext to display time variable

I have a controller variable of time datatype.
public Time startTime{get;set;}

startTime = Time.newInstance(12,0,0,0);
Rendering the variable as is on visualforce will output as 12:00:00.000Z

I want to display this on a visualforce page in a proper time format using the outputText parameter passing technique.
I tried 
<apex:outputText value="{0, time, h:mm a}">
     <apex:param value="{!slot.startTime}" /> 
I'm getting a compile time error "The value attribute on <apex:outputText> is not in a valid format. It must be a positive number, and of type Number, Date, Time, or Choice.". Anybody knows the correct syntax to get this working.

I know we can convert this variable as a datetime variable and use that instead, but wondering why Time variable does not work.

Rahul SharmaRahul Sharma
I don't think formatting works for Time data type, You might have to use date time variable.
Would be good to know the solution tough!
Could you try with this ?

<apex:outputText value="{0,date,dd/MM/yyyy}">
  <apex:param value="{!slot.startTime}" />

Let me know if it works !
Jerun JoseJerun Jose
I had tried this as well. Got compile time errors stating invalid date found or something along those lines.
David OvellaDavid Ovella
try with
<apex:outputField value="{!slot.startTime}"/> or
<apex:outputText value=" {!slot.startTime}"/>  (Can you see the space between " { ?)
Edgar Alberto Romero PopocaEdgar Alberto Romero Popoca
I'm encountering the same problem, did you ever find a solution without having to use a dateTime? 
Jerun JoseJerun Jose
No. I had to resort to using a datetime variable instead.
Sarbjeet Singh HayerSarbjeet Singh Hayer
You can try like this

                            <apex:outputText value="{0,number,00}">
                                <apex:param value="{!Minute(item.Interview_time__c)}" />
                           <apex:outputText rendered="{!HOUR(item.Interview_time__c)<12}">
                           <apex:outputText rendered="{!NOT(HOUR(item.Interview_time__c)<12)}">
Penney RatliffPenney Ratliff
Sarbjeet Singh Hayer - that worked! Thank you