zoukankan      html  css  js  c++  java
  • Java时间和时间戳的相互转换

      

    /* 
    
         * 将时间转换为时间戳
    
         */    
    
        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;
    
        }

    Java时间和时间戳的相互转换

     

    时间转换为时间戳:

    复制代码
        /* 
         * 将时间转换为时间戳
         */    
        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;
        }
  • 相关阅读:
    复习时间
    核反应堆
    假期编程
    剪花布条
    Atcoder Regular Contest 072 C Alice in linear land(思维题)
    xss攻击入门
    转发 DDoS攻防战 (一) : 概述
    XSS跨站脚本攻击
    sql注入
    关于阿里云图片识别接口的demo
  • 原文地址:https://www.cnblogs.com/ylht/p/10197295.html
Copyright © 2011-2022 走看看