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