當前位置: 首頁>>代碼示例>>Java>>正文


Java ZonedDateTime.getNano方法代碼示例

本文整理匯總了Java中java.time.ZonedDateTime.getNano方法的典型用法代碼示例。如果您正苦於以下問題:Java ZonedDateTime.getNano方法的具體用法?Java ZonedDateTime.getNano怎麽用?Java ZonedDateTime.getNano使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.ZonedDateTime的用法示例。


在下文中一共展示了ZonedDateTime.getNano方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getTime

import java.time.ZonedDateTime; //導入方法依賴的package包/類
@Override
public long getTime() {
  ZonedDateTime time = stopWatch.getTime();
  long mSecs = ((time.getDayOfMonth() - 1) * 86400 + time.getHour() * 3600
      + time.getMinute() * 60 + time.getSecond()) * 1000
      + time.getNano() / 1000000;
  /*
   * int offset=time.getOffset().getTotalSeconds();
   * System.out.println(" d:"+(time.getDayOfMonth()-1));
   * System.out.println(" h:"+time.getHour());
   * System.out.println(" m:"+time.getMinute());
   * System.out.println(" s:"+time.getSecond());
   * System.out.println(" n:"+time.getNano());
   * System.out.println(" o:"+offset); System.out.println("ms:"+mSecs);
   */
  return mSecs;
}
 
開發者ID:BITPlan,項目名稱:can4eve,代碼行數:18,代碼來源:JFXStopWatch.java

示例2: isEqual

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private static boolean isEqual(LocalDateTime ldt, Timestamp ts) {
    ZonedDateTime zdt = ZonedDateTime.of(ldt, ZoneId.systemDefault());
    return zdt.getYear() == ts.getYear() + 1900 &&
           zdt.getMonthValue() == ts.getMonth() + 1 &&
           zdt.getDayOfMonth() == ts.getDate() &&
           zdt.getHour() == ts.getHours() &&
           zdt.getMinute() == ts.getMinutes() &&
           zdt.getSecond() == ts.getSeconds() &&
           zdt.getNano() == ts.getNanos();
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:11,代碼來源:JavatimeTest.java

示例3: testMatching

import java.time.ZonedDateTime; //導入方法依賴的package包/類
private static void testMatching(XMLFormatter formatter,
        LogRecord record,  Instant instant, long expectedNanos,
        boolean useInstant) {

    ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
    int zdtNanos = zdt.getNano();
    assertEquals(expectedNanos, zdtNanos, "ZonedDateTime.getNano()");

    String str = formatter.format(record);

    String match = "."+expectedNanos;
    if (str.contains(match) != useInstant) {
        throw new RuntimeException(formatter.getClass().getSimpleName()
                + ".format()"
                + " string does not contain expected nanos: "
                + "\n\texpected match for: '" + match + "'"
                + "\n\tin: \n" + str);
    }
    System.out.println("Found expected match for '"+match+"' in \n"+str);

    match = "<millis>"+instant.toEpochMilli()+"</millis>";
    if (!str.contains(match)) {
        throw new RuntimeException(formatter.getClass().getSimpleName()
                + ".format()"
                + " string does not contain expected millis: "
                + "\n\texpected match for: '" + match + "'"
                + "\n\tin: \n" + str);
    }
    System.out.println("Found expected match for '"+match+"' in \n"+str);

    match = "<nanos>";
    if (str.contains(match) != useInstant) {
        throw new RuntimeException(formatter.getClass().getSimpleName()
                + ".format()"
                + " string "
                + (useInstant
                        ? "does not contain expected nanos: "
                        : "contains unexpected nanos: ")
                + "\n\t" + (useInstant ? "expected" : "unexpected")
                + " match for: '" + match + "'"
                + "\n\tin: \n" + str);
    }
    match = "<nanos>"+getNanoAdjustment(record)+"</nanos>";
    if (str.contains(match) != useInstant) {
        throw new RuntimeException(formatter.getClass().getSimpleName()
                + ".format()"
                + " string "
                + (useInstant
                        ? "does not contain expected nanos: "
                        : "contains unexpected nanos: ")
                + "\n\t" + (useInstant ? "expected" : "unexpected")
                + " match for: '" + match + "'"
                + "\n\tin: \n" + str);
    }
    if (useInstant) {
        System.out.println("Found expected match for '"+match+"' in \n"+str);
    } else {
        System.out.println("As expected '"+match+"' is not present in \n"+str);
    }

    match = useInstant ? DateTimeFormatter.ISO_INSTANT.format(instant)
            : zdt.truncatedTo(ChronoUnit.SECONDS)
                    .format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
    match = "<date>"+match+"</date>";
    if (!str.contains(match)) {
        throw new RuntimeException(formatter.getClass().getSimpleName()
                + ".format()"
                + " string does not contain expected date: "
                + "\n\texpected match for: '" + match + "'"
                + "\n\tin: \n" + str);
    }
    System.out.println("Found expected match for '"+match+"' in \n"+str);

}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:75,代碼來源:XmlFormatterNanos.java


注:本文中的java.time.ZonedDateTime.getNano方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。