【Java】时间类型

Date 转 timeStamp

long time = System.currentTimeMillis();  // 秒级
long time = System.currentTimeMillis()/1000;  // 毫秒
Date date = new Date();
Long timeStamp = date.getTime();  // 毫秒

timeStamp 转 Date

Long timeStamp = 1527767665231L;
Date date = new Date(timeStamp);

Date 转 String

Date date = new Date();
String simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd").format(date);

String 转 Date

String dateStr = "2019-01-03 10:59:27";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = simpleDateFormat.parse(dateStr);  // Thu Jan 03 10:59:27 CST 2019
String pay_time = "2022-12-15T14:35:31+08:00";
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Date parse = formatter.parse(pay_time);  // Thu Dec 15 14:35:31 CST 2022
posted @ 2022-11-18 09:27  小魁jking  阅读(32)  评论(0编辑  收藏  举报