当前位置:主页 > 软件编程 > JAVA代码 >

Java里得到00:00:00格式的时分秒的Timestamp

时间:2021-06-26 08:46:48 | 栏目:JAVA代码 | 点击:

复制代码 代码如下:

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
long t = System.currentTimeMillis();
t = t / (1000 * 3600 * 24) * (1000 * 3600 * 24);
System.out.println(sdf.format(new Timestamp(t)));
t = System.currentTimeMillis();
t = t / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
System.out.println(sdf.format(new Timestamp(t)));
}
}

如果不扣掉时区偏移,那么时间将是北京默认的东8区(GMT+8)

您可能感兴趣的文章:

相关文章