本文整理汇总了Java中java.time.LocalDateTime.getNano方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDateTime.getNano方法的具体用法?Java LocalDateTime.getNano怎么用?Java LocalDateTime.getNano使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDateTime
的用法示例。
在下文中一共展示了LocalDateTime.getNano方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: write
import java.time.LocalDateTime; //导入方法依赖的package包/类
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
int features) throws IOException {
SerializeWriter out = serializer.out;
if (object == null) {
out.writeNull();
} else {
if (fieldType == null) {
fieldType = object.getClass();
}
if (fieldType == LocalDateTime.class) {
final int mask = SerializerFeature.UseISO8601DateFormat.getMask();
LocalDateTime dateTime = (LocalDateTime) object;
String format = serializer.getDateFormatPattern();
if (format == null && (features & mask) != 0 || serializer.isEnabled(SerializerFeature.UseISO8601DateFormat)) {
format = formatter_iso8601_pattern;
}
if (dateTime.getNano() == 0 || format != null) {
if (format == null) {
format = JSON.DEFFAULT_DATE_FORMAT;
}
write(out, dateTime, format);
} else if (out.isEnabled(SerializerFeature.WriteDateUseDateFormat)) {
//使用固定格式转化时间
write(out, dateTime, JSON.DEFFAULT_DATE_FORMAT);
} else {
out.writeLong(dateTime.atZone(JSON.defaultTimeZone.toZoneId()).toInstant().toEpochMilli());
}
} else {
out.writeString(object.toString());
}
}
}
示例2: getTruncatedLocalDateTime
import java.time.LocalDateTime; //导入方法依赖的package包/类
public LocalDateTime getTruncatedLocalDateTime(LocalDateTime value){
if(value == null){
return null;
}
int divideBy = (int) Math.pow(10, TOTAL_NUM_FRACTIONAL_SECONDS - getNumFractionalSeconds());
if(divideBy < 1){
throw new RuntimeException("numFractionalSeconds is greater or equal to 9");
}
int numNanoSeconds = value.getNano() / divideBy * divideBy;
return value.withNano(numNanoSeconds);
}
示例3: valueOf
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
* object, with the same year, month, day of month, hours, minutes,
* seconds and nanos date-time value as the provided {@code LocalDateTime}.
* <p>
* The provided {@code LocalDateTime} is interpreted as the local
* date-time in the local time zone.
*
* @param dateTime a {@code LocalDateTime} to convert
* @return a {@code Timestamp} object
* @exception NullPointerException if {@code dateTime} is null.
* @since 1.8
*/
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
return new Timestamp(dateTime.getYear() - 1900,
dateTime.getMonthValue() - 1,
dateTime.getDayOfMonth(),
dateTime.getHour(),
dateTime.getMinute(),
dateTime.getSecond(),
dateTime.getNano());
}
示例4: of
import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
* Obtains an instance defining a transition between two offsets.
* <p>
* Applications should normally obtain an instance from {@link ZoneRules}.
* This factory is only intended for use when creating {@link ZoneRules}.
*
* @param transition the transition date-time at the transition, which never
* actually occurs, expressed local to the before offset, not null
* @param offsetBefore the offset before the transition, not null
* @param offsetAfter the offset at and after the transition, not null
* @return the transition, not null
* @throws IllegalArgumentException if {@code offsetBefore} and {@code offsetAfter}
* are equal, or {@code transition.getNano()} returns non-zero value
*/
public static ZoneOffsetTransition of(LocalDateTime transition, ZoneOffset offsetBefore, ZoneOffset offsetAfter) {
Objects.requireNonNull(transition, "transition");
Objects.requireNonNull(offsetBefore, "offsetBefore");
Objects.requireNonNull(offsetAfter, "offsetAfter");
if (offsetBefore.equals(offsetAfter)) {
throw new IllegalArgumentException("Offsets must not be equal");
}
if (transition.getNano() != 0) {
throw new IllegalArgumentException("Nano-of-second must be zero");
}
return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}