package org.jh.modules.spt.controller;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class cs {
public static void main(String[] args) throws ParseException {
Date date = new Date();
//获取当前日期
System.out.println("1 " + date);
//获取当前时间戳
System.out.println("2 " + date.getTime());
//获取当前时间年月日
SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd");
System.out.println("3 " + a.format(date));
//获取当前年时间时分秒
SimpleDateFormat b = new SimpleDateFormat("hh:mm:ss");
System.out.println("4 " + b.format(date));
//获取当前年时间年月日时分秒
SimpleDateFormat c = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println("5 " + c.format(date));
//时间戳转换成年月日时分秒
//获取当前时间的时间戳
Date date1 = new Date(System.currentTimeMillis());
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.println("6 " + dateFormat.format(date1));
//年月日换成时间戳
SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date parse = d.parse("2022-01-06 09:20:19");
System.out.println("7 " + parse.getTime());
}
}
-------------------------结果-------------------------
1 Thu Jan 06 09:22:02 CST 2022
2 1641432122241
3 2022-01-06
4 09:22:02
5 2022-01-06 09:22:02
6 2022-01-06 09:22:02
7 1641432019000