我有一个值为“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;
}
我知道这很烦人而且很冗长。我可以以更简单的方式实现要求吗?