
image.png
@[toc]
一、介紹
這段代碼演示了如何將毫秒級(jí)時(shí)間戳(如1570650412089)通過(guò)Date對(duì)象和SimpleDateFormat轉(zhuǎn)換為"年-月-日 時(shí):分:秒"格式的日期字符串,常用于時(shí)間戳解析、日志時(shí)間轉(zhuǎn)換或數(shù)據(jù)格式化展示。
二、代碼
//Long轉(zhuǎn)String(時(shí)間毫秒數(shù)轉(zhuǎn)日期格式字符串)
@Test
void millisecondsTransformString() {
long milliSecond = 1570650412089L;
Date date = new Date();
date.setTime(milliSecond);
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date));
//2019-10-10 03:46:52
}