用 java 读取excel 文件里的时间格式数据时,24时制会自动转化为12时制,解决办法

在用java 读取excel文件时会有这样的情况的发生 文件内容 18:05 读出后 6:05 原因是引用jxl 时有个pattern类用的是12时制的时间,所以...., 要自己写个方法来再次将它读出的时间进行转换.

 

package  blogic;



import  jxl.Cell;
import  jxl.DateCell;
import  jxl.Sheet;
import  jxl.Workbook;
import  jxl.read.biff.BiffException;
import  java.io.IOException;
import  java.io.InputStream;
import  java.text.SimpleDateFormat;
import  java.io.FileInputStream;
import  java.io.File;

/**
 * <概要描述> 倒入考勤表
 * 
 * 
@author xx
 * 
@version 1.0 2008/01/07
 
*/

public   class  readExcel  {
    
/**
     * <概要描述> excle文件中时间类型数据格式转换
     * 
     * 
@param excle文件中时间类型数据
     * 
@return String
     * 
@throws 无
     
*/

    
public static String FormateTime(Cell formatecell) {
        
try {
            java.util.Date mydate 
= null;
            DateCell datecll 
= (DateCell) formatecell;
            mydate 
= datecll.getDate();
            
long time = (mydate.getTime() / 1000- 60 * 60 * 8;
            mydate.setTime(time 
* 1000);
            SimpleDateFormat formatter 
= new SimpleDateFormat("HH:mm");
            
return formatter.format(mydate);
        }
 catch (Exception e) {
            e.printStackTrace();
            
return null;
        }

    }


    
public static void main(String args[]){
        readExcel readexcel
=new readExcel();
        String filePath
="C:/modual.xls";
        readexcel.ReadExcelToDb(filePath);
    }

}

你可能感兴趣的:(ORACLE数据库)