【MapSheep】
[好记性不如烂笔头]
  1. 时间戳与标准时间互相转换
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class timeConvert {
    public static void main(String[] args) throws ParseException {
        // 转换出来的为毫秒格式
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        // 时间戳
        long timeStamp = System.currentTimeMillis();
        // yyyy-MM-dd HH:mm:ss格式
        String sandArd = dateFormat.format(new Date(timeStamp));
        // 时间戳
        long timeStamp02 = dateFormat.parse(sandArd).getTime();


        System.out.println("时间戳: " + timeStamp + ", 转换为yyyy-MM-dd HH:mm:ss格式: " + sandArd);
        // 时间戳: 1625124818870, 转换为yyyy-MM-dd HH:mm:ss格式: 2021-07-01 15:33:38

        System.out.println("yyyy-MM-dd HH:mm:ss: " + sandArd + ", 转换为时间戳格式: " + timeStamp02);
        // yyyy-MM-dd HH:mm:ss: 2021-07-01 15:33:38, 转换为时间戳格式: 1625124818000
    }
}

  1. 按秒转换

    点击跳转至实时转换网站

posted on 2021-07-02 15:24  (Play)  阅读(579)  评论(0编辑  收藏  举报