`

时间类型的转化

 
阅读更多

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String a=df.format(new Date());
        Timestamp ts = new Timestamp(System.currentTimeMillis()); 
        ts.valueOf(a);
        //timestamp 转String
        DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
        String tsStr = ""; 
        try { 
            //方法一 
            tsStr = sdf.format(ts); 
            System.out.println(tsStr); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } 
        System.out.println(ts);
        /**
         * String 转timestamp
         */
        public Timestamp getcurrent() {
            SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String a=df.format(new Date());
            Timestamp ts = new Timestamp(System.currentTimeMillis()); 
            ts.valueOf(a);
            return ts;
        }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics