Date And Number Formatting In Visualforce Pages

Feedback

There would be number of time we need to format the date and time in visualforce page because each country have different way of representing the date and time, for an example some countries have a month in starting of the date or some countries have day in starting of the month, so it’s really important to format date and time in visualforce pages, to format date and time in visualforce page we have to used the outputtext tag in visualforce pages, param tag are used within the outputtext tag that what make param tag value to render as in the format mention in the output text.I have tried some formatting of date and time and the code of that formatting i am giving below.

<apex:page showHeader="true" sidebar="true">
<style>
.tableContent {
border: 1px solid black;
font: 12px, Verdana;
}
.tableHeader {
background-color: black;
font: 16px, Verdana;
color: white;
}
.bold {
font-weight: bold;
}
</style>
	<apex:sectionHeader title="MyHeaderTitle" subtitle="MyHeaderSubTitle" />
	<apex:pageBlock title="MyPageBlockTitle">
                        <table border="0" cellspacing="2" cellpadding="6" class="tableContent">
                        <tr class="tableHeader">
                        <th>
                            Format
                        </th>
                        <th>
                            Input
                        </th>
                        <th>
                            Output
                        </th>
                        </tr>



                        <!--First format  -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, M/d/yyyy}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, M/d/yyyy}">
                                <apex:param  value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>


                        <!-- Second Format -->

                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, M/d/yy}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, M/d/yy}">
                                <apex:param  value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>

                        <!-- 3rd format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, MMMM/d/yyyy}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, MMMM/d/yyyy}">
                                <apex:param  value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>


                        <!-- Fourth Format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, d MMMM/yyyy}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, d MMMM/yyyy}">
                                <apex:param  value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>

                        <!-- Fifth format -->
                        <tr>
                        <td>
                               <apex:outputtext value="{0, date, yyyy-MM-dd}"></apex:outputtext>
                        </td>
                        <td>
                              <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                                <apex:outputtext value="{0, date, yyyy-MM-dd}">
                                <apex:param  value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>




                        <!-- Sixth format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, short}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, short}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>


                        <!-- Seventh format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, medium}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, medium}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>


                        <!-- Eigth format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, long}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, long}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>

                        <!-- Ninth format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, full}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, full}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>

                        <!-- Tenth format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, yyyy-mm-dd hh:mm:ss a}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, yyyy-MMM-dd hh:mm:ss a z}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>


                        <!-- Eleventh  -->

                        <!-- Tenth format -->
                        <tr>
                        <td>
                            <apex:outputtext value="{0, date, yyyy.MM.dd G hh:mm:ss a z}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{!NOW()}"></apex:outputtext>
                        </td>
                        <td>
                            <apex:outputtext value="{0, date, yyyy.MM.dd G hh:mm:ss a z}">
                                <apex:param value="{!NOW()}"></apex:param>
                            </apex:outputtext>
                        </td>
                        </tr>

                        </table>
	</apex:pageBlock>
</apex:page>

The above code would render as the below table, see the below table and choose the type of the format you are looking for.

FormatInputOutput
{0, date, M/d/yyyy}Tue Oct 13 12:12:17 GMT 201510/13/2015
{0, date, M/d/yy}Tue Oct 13 12:12:17 GMT 201510/13/15
{0, date, MMMM/d/yyyy}Tue Oct 13 12:12:17 GMT 2015October/13/2015
{0, date, d MMMM/yyyy}Tue Oct 13 12:12:17 GMT 201513 October/2015
{0, date, yyyy-MM-dd}Tue Oct 13 12:12:17 GMT 20152015-10-13
{0, date, short}Tue Oct 13 12:12:17 GMT 201510/13/15
{0, date, medium}Tue Oct 13 12:12:17 GMT 2015Oct 13, 2015
{0, date, long}Tue Oct 13 12:12:17 GMT 2015October 13, 2015
{0, date, full}Tue Oct 13 12:12:17 GMT 2015Tuesday, October 13, 2015
{0, date, yyyy-mm-dd hh:mm:ss a}Tue Oct 13 12:12:17 GMT 20152015-Oct-13 12:12:17 PM GMT
{0, date, yyyy-mm-dd hh:mm:ss a}Tue Oct 13 12:12:17 GMT 20152015.10.13 AD 12:12:17 PM GMT

That’s it for today post, I hope you like my this post and if you doesn’t find the date and time format which you are looking then let me know I would help you to create Date and time but I believe this information is adequate and it would help you to create your own date and time format.

Related Articles :

Speak Your Mind

*