首页 > 其他分享 >Timestamp

Timestamp

时间:2023-12-21 10:23:31浏览次数:35  
标签:util java Timestamp nanos Date 1000

概述

A thin wrapper around <code>java.util.Date</code> that allows the JDBC API to identify this as an SQL <code>TIMESTAMP</code> value.
It adds the ability to hold the SQL <code>TIMESTAMP</code> fractional seconds value, by allowing the specification of fractional seconds to a precision of nanoseconds.
A Timestamp also provides formatting and parsing operations to support the JDBC escape syntax for timestamp values.

Timestamp是java.util.Date的wrapper,允许JDBC API识别作为一个SQL的时间戳值;

Timestamp提供了持有纳秒值的能力;

 

This type is a composite of a <code>java.util.Date</code> and a separate nanoseconds value.
Only integral seconds are stored in the <code>java.util.Date</code> component.
The fractional seconds - the nanos - are separate.
The <code>Timestamp.equals(Object)</code> method never returns <code>true</code> when passed an object that isn't an instance of <code>java.sql.Timestamp</code>, because the nanos component of a date is unknown.
As a result, the <code>Timestamp.equals(Object)</code> method is not symmetric with respect to the <code>java.util.Date.equals(Object)</code> method.
Also, the <code>hashCode</code> method uses the underlying <code>java.util.Date</code> implementation and therefore does not include nanos in its computation.

Timestamp是Date和纳秒值的组合

整数秒 存在Date中,纳秒是分离的;

Timestamp.equals(Object)时,如果参数不是Timestamp的实例,永远不会返回true,因为没有纳秒值;

hashcode方法使用的是Date的,不包含纳秒;

 

 

public class Timestamp extends java.util.Date {

        private int nanos;
        
        public Timestamp(long time) {
            super((time/1000)*1000);
            nanos = (int)((time%1000) * 1000000);
            if (nanos < 0) {
                nanos = 1000000000 + nanos;
                super.setTime(((time/1000)-1)*1000);
            }
        }

        // Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this <code>Timestamp</code> object.
        public long getTime() {
            long time = super.getTime();
            return (time + (nanos / 1000000));
        }

        // Gets this <code>Timestamp</code> object's <code>nanos</code> value.
        public int getNanos() {
            return nanos;
        }
    }

  

 

标签:util,java,Timestamp,nanos,Date,1000
From: https://www.cnblogs.com/anpeiyong/p/17918392.html

相关文章

  • `pd.Timestamp.now()`和`datetime.datetime.now()`都是用来获取当前时间的函数,但它们
    `pd.Timestamp.now()`和`datetime.datetime.now()`都是用来获取当前时间的函数,但它们之间存在一些差异¹²。-`pd.Timestamp.now()`返回的是Pandas的Timestamp对象,这个对象是在UTC(协调世界时)时区下的当前时间¹²。-`datetime.datetime.now()`返回的是Python的datetime对象,这个......
  • postman内置函数-$timestamp
    引言postman当中有一些内置函数,可以直接使用。介绍$timestamp内置函数用于在请求中插入当前时间戳。它可以用在请求头、请求体、响应头和响应体中。以下是一个使用$timestamp内置函数的示例:POST/api/v1/usersContent-Type:application/json{"name":"JohnDoe",......
  • postman内置函数-$timestamp
    引言postman当中有一些内置函数,可以直接使用。介绍$timestamp内置函数用于在请求中插入当前时间戳。它可以用在请求头、请求体、响应头和响应体中。以下是一个使用$timestamp内置函数的示例:POST/api/v1/usersContent-Type:application/json{"name":"JohnDoe",......
  • [岩禾溪] C++20项目 muduo网络库 项目实战 (1)Logger & Timestamp
    ​  ​编辑本项目由岩禾溪原创 项目实战+新特性用法介绍开源代码+博客解析+视频讲解 GitHub+CSDN+BiliBili同步更新,三个平台同名【岩禾溪】视频讲解和代码链接在文章末尾,你的关注是我更新的最大动力项目环境本项目采用C++20开发精简Muduo网络库BuildTool:Xma......
  • MySQL 8.0 目前仍旧没有解决timestamp时间戳溢出的问题
    在MySQL中,TIMESTAMP列的默认范围是从'1970-01-0100:00:01'到'2038-01-1903:14:07'。如果插入的时间值超出了该范围,MySQL会将其视为无效值,并将其设置为'0000-00-0000:00:00'。在MySQL8.0.35最新版本中,timestamp时间戳溢出的问题目前仍旧没有解决。如下图所示:为了解决这个问题,只......
  • oracle数据库 时间 TIMESTAMP(6)这是什么类型啊 怎么也插不进数据 ,是时间戳类型,参数6
    oracle数据库时间TIMESTAMP(6)这是什么类型啊怎么也插不进数据是时间戳类型,参数6指的是表示秒的数字的小数点右边可以存储6位数字是时间戳类型,参数6指的是表示秒的数字的小数点右边可以存储6位数字,最多9位。解决方法如下:1、时间戳的概念:它是一种时间表示方式,定义为从格林威......
  • timestamp(6)详解 在MySQL中,timestamp是一种时间戳类型。timestamp(6)是timestamp类型
    timestamp(6)详解在MySQL中,timestamp是一种时间戳类型。timestamp(6)是timestamp类型的一个子类型,表示精确到秒后6位小数的时间戳。它占用8个字节存储空间一、什么是timestamp(6)在MySQL中,timestamp是一种时间戳类型。timestamp(6)是timestamp类型的一个子类型,表示精确到秒后6......
  • MySQL timestamp查询
    MySQL是一个常用的关系型数据库管理系统,广泛应用于各个行业的数据存储和处理中。在MySQL中,timestamp是一种常用的数据类型,用于表示日期和时间。本文将介绍如何使用MySQL中的timestamp进行查询操作,并给出相应的代码示例。1.timestamp的概述timestamp是MySQL中的一种日期和时间类......
  • 日期转换工具类:由TimeStamp时间戳转换为日期格式的字符串
    importlombok.extern.slf4j.Slf4j;importorg.apache.commons.lang3.StringUtils;importjava.text.ParseException;importjava.text.SimpleDateFormat;importjava.util.Date;@Slf4jpublicclassDateTimeUtil{publicstaticfinalStringDATE_PATTERN="yyyy-......
  • 如何避免Mysql的timestamp的大坑
    如何避免Mysql的timestamp的大坑Mysql的timestamp类型讨论需要测试MYSQL的同学,可以点以下链接免费试用腾讯云mysql服务器https://curl.qcloud.com/tgnMO3KJ一.时间戳字段定义timestamp时间戳是指格林威治时间1970年01月01日00时00分00秒(北京时间1970年01月01日08时00分00秒)起到......