1 13 package com.tonbeller.jpivot.olap.model.impl; 14 15 import java.text.DecimalFormat ; 16 17 import com.tonbeller.jpivot.olap.model.Cell; 18 import com.tonbeller.jpivot.olap.model.CellFormatter; 19 20 27 public class CF_hhhmmss implements CellFormatter { 28 29 static DecimalFormat f00 = new DecimalFormat ("00"); 30 31 public String formatCell(Cell cell) { 32 long longVal = objToLong(cell.getValue()); 33 34 long hours = longVal / 3600; 35 long secs = longVal % 3600; 36 long mins = secs / 60; 37 secs = secs % 60; 38 String str = Long.toString(hours) + ":" + f00.format(mins) + ":" + f00.format(secs); 39 return str; 40 } 41 42 public static long objToLong(Object obj) { 43 long longVal; 44 if (obj instanceof Double ) 45 longVal = ((Double ) obj).longValue(); 46 else if (obj instanceof Long ) 47 longVal = ((Long ) obj).longValue(); 48 else if (obj instanceof Integer ) 49 longVal = ((Integer ) obj).longValue(); 50 else if (obj instanceof String ) 51 longVal = Long.parseLong((String ) obj); 52 else 53 longVal = 0; 54 return longVal; 55 } 56 } | Popular Tags |