Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中将Mongo changestream中的Bson时间戳转换为UTC日期格式?_Java_Mongodb_Timestamp_Change Data Capture - Fatal编程技术网

如何在Java中将Mongo changestream中的Bson时间戳转换为UTC日期格式?

如何在Java中将Mongo changestream中的Bson时间戳转换为UTC日期格式?,java,mongodb,timestamp,change-data-capture,Java,Mongodb,Timestamp,Change Data Capture,例如:clusterTime=TimeStamp{value=6948482818288648193,seconds=16754329210,inc=1} 当我从document.getClusterTime().toString()读取值时,返回的值是bson timestamp。我想将其转换为UTC时间格式。BSON时间戳值是一个64位数字,其中前32位表示自1970-01-01 Unix纪元00:00 UTC以来的秒数 以下是mongoDB文档的摘录: 时间标记 BSON有一个特殊的时间戳

例如:clusterTime=TimeStamp{value=6948482818288648193,seconds=16754329210,inc=1}


当我从document.getClusterTime().toString()读取值时,返回的值是bson timestamp。我想将其转换为UTC时间格式。

BSON时间戳值是一个64位数字,其中前32位表示自1970-01-01 Unix纪元00:00 UTC以来的秒数

以下是mongoDB文档的摘录:

时间标记 BSON有一个特殊的时间戳类型供内部MongoDB使用 并且与常规日期类型不关联。这个内部 时间戳类型是64位值,其中:

  • 最高有效32位是
    时间\u t
    值(自 Unix时代)
  • 最低有效32位是递增的序数 对于给定秒内的操作
以你为例:

    long timestampValue = 6_948_482_818_288_648_193L;
    
    long unixTimestamp = timestampValue >> 32;
    Instant timestamp = Instant.ofEpochSecond(unixTimestamp);
    
    System.out.println(timestamp);
输出:

2021-04-07T18:22:07Z

打印结果以UTC为单位,由尾部的
Z
表示


链接:

BSON时间戳值是一个64位数字,其中前32位表示自1970-01-01 Unix纪元00:00 UTC以来的秒数

以下是mongoDB文档的摘录:

时间标记 BSON有一个特殊的时间戳类型供内部MongoDB使用 并且与常规日期类型不关联。这个内部 时间戳类型是64位值,其中:

  • 最高有效32位是
    时间\u t
    值(自 Unix时代)
  • 最低有效32位是递增的序数 对于给定秒内的操作
以你为例:

    long timestampValue = 6_948_482_818_288_648_193L;
    
    long unixTimestamp = timestampValue >> 32;
    Instant timestamp = Instant.ofEpochSecond(unixTimestamp);
    
    System.out.println(timestamp);
输出:

2021-04-07T18:22:07Z

打印结果以UTC为单位,由尾部的
Z
表示


链接:

谢谢你的解决方案你是对的,该死的细节。。。然而,BSON有一种特殊的时间戳类型供内部MongoDB使用,因此
时间戳
非常少见。感谢您的解决方案,该死的细节。。。然而,BSON有一种特殊的时间戳类型供内部MongoDB使用,因此
时间戳
非常少见。