本文转载自https://www.cnblogs.com/mstk/p/5511057.html,如有侵权联系删除!

时间转换为时间戳:

 

   /* 
     * 将时间转换为时间戳
     */    
    public static String dateToStamp(String s) throws ParseException{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime();
        res = String.valueOf(ts);
        return res;
    }

 

 

 

时间戳转换为时间:

 

   /* 
     * 将时间戳转换为时间
     */
    public static String stampToDate(String s){
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        long lt = new Long(s);
        Date date = new Date(lt);
        res = simpleDateFormat.format(date);
        return res;
    }

 

 

相关文章:

  • 2022-12-23
  • 2021-12-05
  • 2021-11-28
  • 2022-02-21
  • 2021-12-30
  • 2021-08-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案