package com.example.demo.lz.test; import java.text.SimpleDateFormat; import java.util.Date; /** * @author: create by lz * @copyright: c * @date:2020/5/14 10:50 */ public class Main5 { public static void main(String[] args) { String s = "1382694957";//时间戳 long l = Long.parseLong(s);//字符串转long Date date = new Date(l);//时间戳转日期 Date date1 = new Date();//当前日期 SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println(date); System.out.println(date1); System.out.println(df.format(date)); System.out.println(df.format(date1)); } }
打印输出
Sat Jan 17 08:04:54 CST 1970
Thu May 14 10:55:59 CST 2020
1970-01-17 08:04:54
2020-05-14 10:55:59