package com.zzsn.test;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TimePaser {

    public static void main(String[] args) throws Exception{
//        String aa="2022-04-18";
//        String s = dateToStamp(aa);
//        System.out.println(s);
        Date date = new Date();
        String nowTime="";
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/dd/yyyy");
//        String format = simpleDateFormat.format("1650384000");
        System.out.println(stampToTime("1650384000"));
    }
    public static String dateToStamp(String s) throws ParseException {
        String res;
        //设置时间模版
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/dd/yyyy");
        Date date = simpleDateFormat.parse(s);
        long ts = date.getTime()/1000;
        res = String.valueOf(ts);
        return res;
    }
    //将时间戳转换为时间
    public static String stampToTime(String s) throws Exception{
        String res;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("M/dd/yyyy");
        long lt = new Long(s);
        //将时间戳转换为时间
        Date date = new Date(lt*1000);
        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
        res = simpleDateFormat.format(date);
        return res;
    }

}
