gpt4 book ai didi

java - 日期与纳米时间戳

转载 作者:行者123 更新时间:2023-11-30 10:44:26 26 4
gpt4 key购买 nike

我想将日期转换为时间戳以设置变量。我有以下代码,但似乎无效。

Date org_last_upd_ts=xxxxxxx;

SimpleDateFormat sdf=new SimpleDateFormat("SSSSSS");
Timestamp org_lastupdts=new Timestamp(org_last_upd_ts.getTime());
org_lastupdts.setNanos(Integer.valueOf(sdf.parse(o rg_last_upd_ts.toLocaleString()).toString()));

知道怎么做吗?

最佳答案

你可以这样转换

java.util.Date now = new Date();
java.sql.Timestamp timestamp = new Timestamp(now.getTime());

来自 javadoc Timestamp constructor

Constructs a Timestamp object using a milliseconds time value. The integral seconds are stored in the underlying date value; the fractional seconds are stored in the nanos field of the Timestamp object.

关于java - 日期与纳米时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37390283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com