Play Games

Search This Blog

Friday, December 9, 2016

How to get time from Datetime field in apex salesforce

Solution : Use field.format('h:mm a') to get time from DateTime field
Example:
Apex Class:
public class TimeController {
    public String sTime {get;set;}
    public String sTime1 {get;set;}
    public TimeController (){
        DateTime dtDateTime = system.now();
        sTime = dtDateTime.format('h:mm a');
        sTime1 = dtDateTime.format('h:mm');
    }
}
Visualforce Page :
<apex:page controller="TimeController">
Note The time is getting displayed :<b> {!sTime} </b><br/>
Note The time is getting displayed :<b>{!sTime1} </b>
</apex:page>
Output:

No comments:

Post a Comment