JAVA Instant类型 转换 Timestamp类型 时间戳

东林梁

关注

阅读 122

2022-01-13

package com.test;

import java.sql.Timestamp;
import java.time.Instant;

public class test1 {

	public static void main(String[] args) {
		
		//Timestamp 的参数是毫秒,Instant 获得的是秒
		System.out.println(new Timestamp(Instant.now().getEpochSecond()*1000L));
		System.out.println(new Timestamp(Instant.now().getEpochSecond()*1000));
		System.out.println(new Timestamp(Instant.now().getEpochSecond()));
		System.out.println(new Timestamp(0));
		
		//结果
//		2022-01-13 13:26:29.0
//		2022-01-13 13:26:29.0
//		1970-01-20 08:07:31.589
//		1970-01-01 08:00:00.0

	}

}

精彩评论(0)

0 0 举报