function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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}" /> 
</apex:outputText>
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!
vinsrivvinsriv
Could you try with this ?

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

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

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