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
Mathew Andresen 5Mathew Andresen 5 

Displayed date different from what is entered

Hi,

I have a date time field that when I display in visualforce doesn't always show the correct date.  If the time I enter is 4:00 PM or later it displays the next days date.

My company time and user times are both PST (GMT + 8)
 
<apex:outputText value="{0,date,MM'/'dd'/'yyyy}"> <apex:param value="{!v.tasting.Date_of_Tasting_Start__c}" />

Any ideas?
 
Best Answer chosen by Mathew Andresen 5
Himanshu ParasharHimanshu Parashar
Hey Mathew,

You need to use following component  show that in correct way

1. Create following controller
public class MFSI_FormatDateTime {
    public DateTime dateTimeValue { get; set; }
    public String getTimeZoneValue() {
        if( dateTimeValue != null ) {
            String localeFormatDT = dateTimeValue.format();
            return localeFormatDT;
        }
        return null;
    }
}

2. Create following visualforce component
 
<apex:component access="global" controller="MFSI_FormatDateTime">
     <apex:attribute assignTo="{!dateTimeValue}" description="The DateTime value to be rendered based upon the user's
               locale" name="date_Timevalue" type="DateTime"></apex:attribute>
       {!TimeZoneValue}
</apex:component>

3. Use in following way.
 
<c:MFSI_FormatDateTime date_Timevalue="{!v.tasting.Date_of_Tasting_Start__c}"/>

Thanks,
Himanshu

All Answers

Himanshu ParasharHimanshu Parashar
Hey Mathew,

You need to use following component  show that in correct way

1. Create following controller
public class MFSI_FormatDateTime {
    public DateTime dateTimeValue { get; set; }
    public String getTimeZoneValue() {
        if( dateTimeValue != null ) {
            String localeFormatDT = dateTimeValue.format();
            return localeFormatDT;
        }
        return null;
    }
}

2. Create following visualforce component
 
<apex:component access="global" controller="MFSI_FormatDateTime">
     <apex:attribute assignTo="{!dateTimeValue}" description="The DateTime value to be rendered based upon the user's
               locale" name="date_Timevalue" type="DateTime"></apex:attribute>
       {!TimeZoneValue}
</apex:component>

3. Use in following way.
 
<c:MFSI_FormatDateTime date_Timevalue="{!v.tasting.Date_of_Tasting_Start__c}"/>

Thanks,
Himanshu
This was selected as the best answer
Mathew Andresen 5Mathew Andresen 5
awesome thanks!