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
Sachin10Sachin10 

Formatting a String to Date in Visualforce Page

I have a string value that gets dispalyed in Visualforce 2011-10-18 02:29:54
I want to convert this into date.

I tried using outputText but i'm geetting the below 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.

Psuedo Code:
<apex:outputText value="{0, date, MMMM d','  yyyy}">
<apex:param value="{!dateTimeVal}"/>
</apex:outputText>

Converting it into time format in the apex controller is NOT a viable option in my case.
So please help the string to get it formatted in the VF page itself.

Any pointers/help is much appreciated.
Many thanks in advance!
Chinmay BhusariChinmay Bhusari
Hi,
Try using type conversion as DateTime is datatype in apex
Sachin10Sachin10
@Chinamy,
Thanks for your reply.
But I want to do it in the VF page, not in Apex.
Let me know if we can convert in VF page with some sample example.

AshwaniAshwani
Sachin,

You can not format a String to date directly in visulforce page. You have to first convert String into DateTime or Date type then you can show the date as:

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



Sachin10Sachin10
@Avillion Thanks for your reply.
Ya I know that we can do it in Apex.But just wanted to be sure if we have no way to achieve it in VF Page.
Looks making change in apex is the only way out here.
Any Idea how to convert the string to a format like this 2/10/2012 8:09 AM?
Basically I need to get the AM & PM.

Thanks in advance :)