The Time class in Salesforce is very limited, especially compared to the DateTime class. It doesn't even have its own format method, which I think may be the underlying problem here. Without a format method to accept the formatting string, Salesforce might not be able to properly format the field.
So I have created a method which will convert the time in AM/PM and it will show on the vf page as it is formatted.
public String formatedTime(Time timeValue){
String hh;
String mm;
String ampm;
if(timeValue != null){
if(timeValue.hour() <= 12){
if(timeValue.hour() == 0){
hh = String.valueOf(timeValue.hour() + 12);
}else{
hh = String.valueOf(timeValue.hour());
}
}
else{
hh = String.valueOf(timeValue.hour() - 12);
}
if(timeValue.minute() < 10){
mm = '0'+String.valueOf(timeValue.minute());
}
else{
mm = String.valueOf(timeValue.minute());
}
if(timeValue.hour() < 12){
ampm = 'AM';
}
else{
ampm = 'PM';
}
return hh+':'+mm+' '+ampm;
}else{
return '';
}
}
Comments
Post a Comment