700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > Java时间戳转换为日期

Java时间戳转换为日期

时间:2018-07-15 02:27:34

相关推荐

Java时间戳转换为日期

当前时间时间戳转换为日期

//当前时间毫秒的时间戳转换为日期Date millisecondDate= new Date(System.currentTimeMillis());//格式化时间SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String millisecondStrings = formatter.format(millisecondDate);System.out.println(millisecondStrings);

//当前时间秒的时间戳转换为日期

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//字符串类型的秒级时间戳String currentTime = "1657519062";Long date = Long.valueOf(currentTime);//String类型String date_time = formatter.format(new Date(date*1000L));System.out.println(date_time);//Date类型Date times=formatter.parse(date_time);System.out.println(times);//Date转为LocalDateTime类型Instant instant = times.toInstant();ZoneId zoneId = ZoneId.systemDefault();LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();

System.out.println(localDateTime );

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。