1
我有值爲「3D7H40M20S」 哪些應該被轉換爲3天7小時40分20秒」的字符串 這裏是我試過至今:如何格式化持續時間字符串?
BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();
AttributeBinding attr = (AttributeBinding)bindings.getControlBinding("ScreeningSLAWaitTimeDuration");
scrSlaWaitDur = (String)attr.getInputValue();
System.out.println("-------------------------------------------SCREENING SLA WAIT DURATION---------------"+scrSlaWaitDur);
scrSlaWaitDur = scrSlaWaitDur.substring(2, scrSlaWaitDur.length());
System.out.println("--------------------------------------------SUBSTRING--------------------"+scrSlaWaitDur);
int dIndex = scrSlaWaitDur.indexOf("D");
System.out.println("*******************************************INDEX OF D**********************************"+dIndex);
if(dIndex != -1){
String newDur = scrSlaWaitDur.substring(0, dIndex)+" days "+scrSlaWaitDur.substring(dIndex+1);
int mIndex = scrSlaWaitDur.lastIndexOf("M");
String newDur2 = scrSlaWaitDur.substring(0, mIndex)+" minute "+scrSlaWaitDur.substring(mIndex+1);
int sIndex = newDur2.lastIndexOf("S");
String newDur3 = newDur2.substring(0,sIndex)+" second";
scrSlaWaitDur = newDur3;
return scrSlaWaitDur;
}
我知道這是相當?煩人和相當長 我能做到的要求以更簡單的方式