java中时间戳、日期、字符串之间转换

xiaoxiao2025-04-20  14

日期Date格式、字符串格式、时间戳 1、Date格式--->字符串格式 2、Date格式--->时间戳 3、字符串格式--->Date格式 4、字符串格式--->时间戳 5、时间戳--->Date格式 6、时间戳--->字符串格式

1、Date格式--->字符串格式

String format = "现在是yyyy-MM-dd的HH:mm:ss"; Date now = new Date();//Thu Oct 18 17:17:49 CST 2018 String nowStr = new SimpleDateFormat(format).format(now);//2018-10-18 17:19:21

2、Date格式--->时间戳

Date now = new Date(); long time = now.getTime();//1540970687235 String stampsNow = String.valueOf(time/1000);//1540970687 long stamp = System.currentTimeMillis();//当前时间戳(ms) String stamps = String.valueOf(stamp/1000);

 

转载请注明原文地址: https://www.6miu.com/read-5028683.html

最新回复(0)