zoukankan      html  css  js  c++  java
  • 时间戳与时间相互转换

    Java时间和时间戳的相互转换(点击查看原文

    时间转换为时间戳:

    按 Ctrl+C 复制代码
    /* 
         * 将时间转换为时间戳
         */    
        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;
        }
    

    按 Ctrl+C 复制代码

    时间戳转换为时间:

    按 Ctrl+C 复制代码
    /* 
         * 将时间戳转换为时间
         */
        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;
        }
    

    按 Ctrl+C 复制代码

    根据第几天去算某年某月某日:

    按 Ctrl+C 复制代码
    formatDate(year,day){//根据第几天去算某年某月某日
    	var dateStr = ‘’;
    	var time = new Date (‘${year}-1-1’).getTime() +(3600*1000*24*day);
    	console.log(time);
    	var m = new Date(time).getMonth() + 1;
    	var d = new Date(time).getDate() + 1;
    	dateStr = ${year}/${m}/${d};
    return dateStr;
    }
    

    按 Ctrl+C 复制代码
    我就是我,不一样的烟火。
  • 相关阅读:
    ConcurrentSkipListMap 源码分析
    ConcurrentHashMap 源码分析
    CopyOnWriteArrayList 源码分析
    AtomicBoolean 源码分析
    commons-lang3-3.4.jar
    Effective Java
    FindBugs Bug Descriptions
    EasyMock
    Apache Maven 入门
    Eclipse
  • 原文地址:https://www.cnblogs.com/Lsr-0220/p/6839839.html
Copyright © 2011-2022 走看看