Lsr-0220

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 复制代码

 

分类:

技术点:

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-21
  • 2021-08-02
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-13
  • 2021-09-29
相关资源
相似解决方案