1

I have two date/time fields which hold the duration of an event (i.e. start time = 11/11/14 12:00, end time = 11/11/14 18:00)

I would like to display this as 12:00 - 18:00 on my force.com page, how can I do this via outputText?

EDIT
This is the code I am currently using:

visualforce

<apex:page showheader="false" controller="force_NewsController" title="News Archive" >
<apex:composition template="{!$Site.Template}">
<apex:define name="body">  
...
            <apex:form id="pgBlock">
            <apex:repeat value="{!newsitems}" var="article" id="theRepeat">
...
                                <apex:outputText value="{!article.Event_Date_Start__c}" />
                                <apex:outputText value="{0,date,HH:mm } - {1,date,HH:mm }">
                                    <apex:param value="{!article.Event_Date_Start__c}" /> 
                                    <apex:param value="{!article.Event_Date_End__c}" />
                                </apex:outputText>
...

controller

public with sharing class force_NewsController {
    public list<News__c> lstItem {get;set;}
    public map<id,string> newsmap{get;set;}

...


    public list<News__c> getNewsItems(){
        lstItem = new list<News__c>();

        String category = Apexpages.currentPage().getParameters().get('cat');
        String query = 'SELECT Id, Name, Title__C, Content__c, Publish_Date__c, Category__c, Event_Date_Start__c, Event_Date_End__c, ';
        query += '(Select Id, Name, LastModifiedDate From Attachments Order By LastModifiedDate DESC) ';
        query += 'FROM News__c ';

        lstItem = Database.query(query);
        return lstItem;
    }

...

I have checked to make sure the view and field level security allow the profile to view the data also but I am still unable to view the data.

  • 1
    Have you any code showing what you have tried already using apex:outputText? – BarCotter Nov 10 '14 at 16:05
  • 1
    ... and if not How to format a date in VisualForce? should get you started. – Keith C Nov 10 '14 at 16:27
  • @BarCotter I have included the code I currently have, which is not working at the minute. – Deployment Failure Nov 11 '14 at 9:46
  • Your code looks fine to me. Can you add more information as to whats happening? – BarCotter Nov 11 '14 at 10:20
  • @BarCotter I've added some more info as requested – Deployment Failure Nov 11 '14 at 10:30
0
<apex:outputText value="{0,date,HH:mm } - {1,date,HH:mm }">
         <apex:param value="{!article.Event_Date_Start__c}" /> 
         <apex:param value="{!article.Event_Date_END__c}" />
</apex:outputText>
1

If you are having two time fields called starttime and endtime, you can create a string variable in your controller to hold the duration.

String duration = starttime.format('h:mm a')+ ' - ' + endtime.format('h:mm a');

You can call the variable in your visualforce page.

<apex:outputText value="{!duration}"/>
0

You can try this !

 <apex:outputText value="{0,time,HH:mm }">
                  <apex:param value="YOUR DATE TIME FIELD" /> 
 </apex:outputText>

The below link would help you out with the different formatting options http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_outputText.htm

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.