com.google.cloud.Timestamp.toDate()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(218)

本文整理了Java中com.google.cloud.Timestamp.toDate()方法的一些代码示例,展示了Timestamp.toDate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Timestamp.toDate()方法的具体详情如下:
包路径:com.google.cloud.Timestamp
类名称:Timestamp
方法名:toDate

Timestamp.toDate介绍

[英]Returns a new java.util.Date corresponding to this timestamp. Any sub-millisecond precision will be stripped.
[中]返回一个新的java。util。与此时间戳对应的日期。任何亚毫秒精度都将被去除。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

  1. /**
  2. * Returns the value of the field as a Date.
  3. *
  4. * <p>This method ignores the global setting {@link
  5. * FirestoreOptions#areTimestampsInSnapshotsEnabled}.
  6. *
  7. * @param field The path to the field.
  8. * @throws RuntimeException if the value is not a Date.
  9. * @return The value of the field.
  10. */
  11. @Nullable
  12. public Date getDate(@Nonnull String field) {
  13. return ((Timestamp) get(field)).toDate();
  14. }

代码示例来源:origin: googleapis/google-cloud-java

  1. private static Date convertDate(Object o, ErrorPath path) {
  2. if (o instanceof Date) {
  3. return (Date) o;
  4. } else if (o instanceof Timestamp) {
  5. return ((Timestamp) o).toDate();
  6. } else {
  7. throw deserializeError(
  8. path, "Failed to convert value of type " + o.getClass().getName() + " to Date");
  9. }
  10. }

代码示例来源:origin: googleapis/google-cloud-java

  1. private Object convertToDateIfNecessary(Object decodedValue) {
  2. if (decodedValue instanceof Timestamp) {
  3. if (!this.firestore.areTimestampsInSnapshotsEnabled()) {
  4. decodedValue = ((Timestamp) decodedValue).toDate();
  5. }
  6. }
  7. return decodedValue;
  8. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void toDate() {
  3. Timestamp timestamp = Timestamp.ofTimeSecondsAndNanos(TEST_TIME_SECONDS, 1234 * 1000);
  4. Date date = timestamp.toDate();
  5. assertThat(TEST_TIME_MILLISECONDS).isEqualTo(date.getTime());
  6. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void deserializesDates() throws Exception {
  3. doAnswer(getAllResponse(ALL_SUPPORTED_TYPES_PROTO))
  4. .when(firestoreMock)
  5. .streamRequest(
  6. getAllCapture.capture(),
  7. streamObserverCapture.capture(),
  8. Matchers.<ServerStreamingCallable>any());
  9. DocumentSnapshot snapshot = documentReference.get().get();
  10. doReturn(false).when(firestoreMock).areTimestampsInSnapshotsEnabled();
  11. assertEquals(DATE, snapshot.get("dateValue"));
  12. assertEquals(TIMESTAMP.toDate(), snapshot.get("timestampValue"));
  13. assertEquals(DATE, snapshot.getData().get("dateValue"));
  14. assertEquals(TIMESTAMP.toDate(), snapshot.getData().get("timestampValue"));
  15. doReturn(true).when(firestoreMock).areTimestampsInSnapshotsEnabled();
  16. assertEquals(Timestamp.of(DATE), snapshot.get("dateValue"));
  17. assertEquals(TIMESTAMP, snapshot.get("timestampValue"));
  18. assertEquals(Timestamp.of(DATE), snapshot.getData().get("dateValue"));
  19. assertEquals(TIMESTAMP, snapshot.getData().get("timestampValue"));
  20. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void queryWithMicrosecondPrecision() throws Exception {
  3. Timestamp microsecondTimestamp = Timestamp.ofTimeSecondsAndNanos(0, 123000);
  4. DocumentReference documentReference = addDocument("time", microsecondTimestamp);
  5. DocumentSnapshot documentSnapshot = documentReference.get().get();
  6. Query query = randomColl.whereEqualTo("time", microsecondTimestamp);
  7. QuerySnapshot querySnapshot = query.get().get();
  8. assertEquals(1, querySnapshot.size());
  9. // Using `.toDate()` truncates to millseconds, and hence the query doesn't match.
  10. query = randomColl.whereEqualTo("time", microsecondTimestamp.toDate());
  11. querySnapshot = query.get().get();
  12. assertEquals(0, querySnapshot.size());
  13. }

代码示例来源:origin: com.google.cloud/google-cloud-firestore

  1. private Object convertToDateIfNecessary(Object decodedValue) {
  2. if (decodedValue instanceof Timestamp) {
  3. if (!this.firestore.areTimestampsInSnapshotsEnabled()) {
  4. decodedValue = ((Timestamp) decodedValue).toDate();
  5. }
  6. }
  7. return decodedValue;
  8. }

代码示例来源:origin: com.google.cloud/google-cloud-firestore

  1. private static Date convertDate(Object o, ErrorPath path) {
  2. if (o instanceof Date) {
  3. return (Date) o;
  4. } else if (o instanceof Timestamp) {
  5. return ((Timestamp) o).toDate();
  6. } else {
  7. throw deserializeError(
  8. path, "Failed to convert value of type " + o.getClass().getName() + " to Date");
  9. }
  10. }

代码示例来源:origin: com.google.cloud/google-cloud-firestore

  1. /**
  2. * Returns the value of the field as a Date.
  3. *
  4. * <p>This method ignores the global setting {@link
  5. * FirestoreOptions#areTimestampsInSnapshotsEnabled}.
  6. *
  7. * @param field The path to the field.
  8. * @throws RuntimeException if the value is not a Date.
  9. * @return The value of the field.
  10. */
  11. @Nullable
  12. public Date getDate(@Nonnull String field) {
  13. return ((Timestamp) get(field)).toDate();
  14. }

相关文章