本文整理汇总了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;
}
示例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();
}
示例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);
}