0
点赞
收藏
分享

微信扫一扫

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

东林梁 2022-01-13 阅读 122
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 条评论