当前位置: 首页>>代码示例>>Java>>正文


Java LocalDateTime.getNano方法代码示例

本文整理汇总了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());
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:37,代码来源:Jdk8DateCodec.java

示例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);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:12,代码来源:LocalDateTimeField.java

示例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());
}
 
开发者ID:madHEYsia,项目名称:ClassroomFlipkart,代码行数:24,代码来源:Timestamp.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:ZoneOffsetTransition.java


注:本文中的java.time.LocalDateTime.getNano方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。