簡體   English   中英

java帶字符串到時間戳:錯誤7秒?

[英]java take String to Timestamp : error of 7 seconds?

我嘗試在時間戳中轉換字符串,我這樣做:

public static Timestamp transfStringToTimestamp(String dateDerniereModifDB2Param, LogWSDTO logWSDTO) throws ExceptionWS {

    Timestamp dateDerniereModifDB2 = null;      
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSSSSS");              
    if (dateDerniereModifDB2Param != null) 
    {
        try 
        {               
            System.out.println("              *********** param : " + dateDerniereModifDB2Param);

            long qu = sdf.parse(dateDerniereModifDB2Param).getTime();

            dateDerniereModifDB2 = new Timestamp(qu);

            System.out.println("            *************** renvoi : " + dateDerniereModifDB2);



        } catch (Exception e) {
            throw new ExceptionWS("ERREUR chaine Timestamp sur méthode transfStringToTimestamp() sur Web Service UtilDate",e, logWSDTO);
        }
    }   

    return dateDerniereModifDB2;
}

作為回報,我有這個:參數:2012-12-04-16.05.30.501455 renvoi:2012-12-04 16:13:51.455

你有個主意嗎? 謝謝 !

501455 milliseconds = 501 seconds and 455 milliseconds
                    = 8 minutes, 21 seconds and 455 milliseconds

SimpleDateFormatSSS部分僅適用於毫秒

嘗試使用日期:

try{
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-HH.mm.ss.SSSSS");
    Date parsedDate = sdf.parse(dateDerniereModifDB2Param);
    Timestamp timestamp = new Timestamp(parsedDate.getTime());
}catch(Exception e){

}

希望對您有所幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM