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

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

本文整理了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

/**
 * Returns the value of the field as a Date.
 *
 * <p>This method ignores the global setting {@link
 * FirestoreOptions#areTimestampsInSnapshotsEnabled}.
 *
 * @param field The path to the field.
 * @throws RuntimeException if the value is not a Date.
 * @return The value of the field.
 */
@Nullable
public Date getDate(@Nonnull String field) {
 return ((Timestamp) get(field)).toDate();
}

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

private static Date convertDate(Object o, ErrorPath path) {
 if (o instanceof Date) {
  return (Date) o;
 } else if (o instanceof Timestamp) {
  return ((Timestamp) o).toDate();
 } else {
  throw deserializeError(
    path, "Failed to convert value of type " + o.getClass().getName() + " to Date");
 }
}

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

private Object convertToDateIfNecessary(Object decodedValue) {
 if (decodedValue instanceof Timestamp) {
  if (!this.firestore.areTimestampsInSnapshotsEnabled()) {
   decodedValue = ((Timestamp) decodedValue).toDate();
  }
 }
 return decodedValue;
}

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

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

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

@Test
public void deserializesDates() throws Exception {
 doAnswer(getAllResponse(ALL_SUPPORTED_TYPES_PROTO))
   .when(firestoreMock)
   .streamRequest(
     getAllCapture.capture(),
     streamObserverCapture.capture(),
     Matchers.<ServerStreamingCallable>any());
 DocumentSnapshot snapshot = documentReference.get().get();
 doReturn(false).when(firestoreMock).areTimestampsInSnapshotsEnabled();
 assertEquals(DATE, snapshot.get("dateValue"));
 assertEquals(TIMESTAMP.toDate(), snapshot.get("timestampValue"));
 assertEquals(DATE, snapshot.getData().get("dateValue"));
 assertEquals(TIMESTAMP.toDate(), snapshot.getData().get("timestampValue"));
 doReturn(true).when(firestoreMock).areTimestampsInSnapshotsEnabled();
 assertEquals(Timestamp.of(DATE), snapshot.get("dateValue"));
 assertEquals(TIMESTAMP, snapshot.get("timestampValue"));
 assertEquals(Timestamp.of(DATE), snapshot.getData().get("dateValue"));
 assertEquals(TIMESTAMP, snapshot.getData().get("timestampValue"));
}

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

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

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

private Object convertToDateIfNecessary(Object decodedValue) {
 if (decodedValue instanceof Timestamp) {
  if (!this.firestore.areTimestampsInSnapshotsEnabled()) {
   decodedValue = ((Timestamp) decodedValue).toDate();
  }
 }
 return decodedValue;
}

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

private static Date convertDate(Object o, ErrorPath path) {
 if (o instanceof Date) {
  return (Date) o;
 } else if (o instanceof Timestamp) {
  return ((Timestamp) o).toDate();
 } else {
  throw deserializeError(
    path, "Failed to convert value of type " + o.getClass().getName() + " to Date");
 }
}

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

/**
 * Returns the value of the field as a Date.
 *
 * <p>This method ignores the global setting {@link
 * FirestoreOptions#areTimestampsInSnapshotsEnabled}.
 *
 * @param field The path to the field.
 * @throws RuntimeException if the value is not a Date.
 * @return The value of the field.
 */
@Nullable
public Date getDate(@Nonnull String field) {
 return ((Timestamp) get(field)).toDate();
}

相关文章