Before passing the parameter check wheather the parameter contains 'PM' or not. You can use String.valueOf(date).contains('PM')
public static String getPMTime(String timeToConvertToPm) { System.debug('>>>>>>>>>><><><><><><><><><><><>timeToConvertToPm'+timeToConvertToPm); decimal x= decimal.valueOf((timeToConvertToPm.subStringBefore(' ')).replace(':','.')); if(!timeToConvertToPm.subStringBefore(':').contains('12')){ x=x+12; } String newTime=String.valueOf(x); newTime=newTime.replace('.',':'); System.debug('>>>>>>>>>><><><><><><><><><><><>newTime'+newTime); return newTime; }
No comments:
Post a Comment