+ Start a Discussion

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}"/>

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
Try using type conversion as DateTime is datatype in apex
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.


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}">
        <apex:param value="{!con.CreatedDate}" />

@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 :)