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


Java ZoneOffset.ofTotalSeconds方法代码示例

本文整理汇总了Java中java.time.ZoneOffset.ofTotalSeconds方法的典型用法代码示例。如果您正苦于以下问题:Java ZoneOffset.ofTotalSeconds方法的具体用法?Java ZoneOffset.ofTotalSeconds怎么用?Java ZoneOffset.ofTotalSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.ZoneOffset的用法示例。


在下文中一共展示了ZoneOffset.ofTotalSeconds方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readExternal

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Reads the state from the stream.
 *
 * @param in  the input stream, not null
 * @return the created object, not null
 * @throws IOException if an error occurs
 */
static ZoneOffsetTransitionRule readExternal(DataInput in) throws IOException {
    int data = in.readInt();
    Month month = Month.of(data >>> 28);
    int dom = ((data & (63 << 22)) >>> 22) - 32;
    int dowByte = (data & (7 << 19)) >>> 19;
    DayOfWeek dow = dowByte == 0 ? null : DayOfWeek.of(dowByte);
    int timeByte = (data & (31 << 14)) >>> 14;
    TimeDefinition defn = TimeDefinition.values()[(data & (3 << 12)) >>> 12];
    int stdByte = (data & (255 << 4)) >>> 4;
    int beforeByte = (data & (3 << 2)) >>> 2;
    int afterByte = (data & 3);
    LocalTime time = (timeByte == 31 ? LocalTime.ofSecondOfDay(in.readInt()) : LocalTime.of(timeByte % 24, 0));
    ZoneOffset std = (stdByte == 255 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds((stdByte - 128) * 900));
    ZoneOffset before = (beforeByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + beforeByte * 1800));
    ZoneOffset after = (afterByte == 3 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(std.getTotalSeconds() + afterByte * 1800));
    return ZoneOffsetTransitionRule.of(month, dom, dow, time, timeByte == 24, defn, std, before, after);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:25,代码来源:ZoneOffsetTransitionRule.java

示例2: with

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public ChronoZonedDateTime<C> with(DateTimeField field, long newValue) {

  if (field instanceof ChronoField) {
    ChronoField f = (ChronoField) field;
    switch (f) {
      case INSTANT_SECONDS:
        return plus(newValue - toEpochSecond(), SECONDS);
      case OFFSET_SECONDS: {
        ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue));
        return create(this.dateTime.toInstant(offset), this.zoneId);
      }
    }
    return ofBest(this.dateTime.with(field, newValue), this.zoneId, this.offset);
  }
  return getDate().getChrono().ensureChronoZonedDateTime(field.doWith(this, newValue));
}
 
开发者ID:kiegroup,项目名称:optashift-employee-rostering,代码行数:18,代码来源:ChronoZonedDateTimeImpl.java

示例3: parseOffsetBased

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Parse an offset following a prefix and set the ZoneId if it is valid.
 * To matching the parsing of ZoneId.of the values are not normalized
 * to ZoneOffsets.
 *
 * @param context the parse context
 * @param text the input text
 * @param prefixPos start of the prefix
 * @param position start of text after the prefix
 * @param parser parser for the value after the prefix
 * @return the position after the parse
 */
private int parseOffsetBased(DateTimeParseContext context, CharSequence text, int prefixPos, int position, OffsetIdPrinterParser parser) {
    String prefix = text.toString().substring(prefixPos, position).toUpperCase();
    if (position >= text.length()) {
        context.setParsed(ZoneId.of(prefix));
        return position;
    }

    // '0' or 'Z' after prefix is not part of a valid ZoneId; use bare prefix
    if (text.charAt(position) == '0' ||
        context.charEquals(text.charAt(position), 'Z')) {
        context.setParsed(ZoneId.of(prefix));
        return position;
    }

    DateTimeParseContext newContext = context.copy();
    int endPos = parser.parse(newContext, text, position);
    try {
        if (endPos < 0) {
            if (parser == OffsetIdPrinterParser.INSTANCE_ID_Z) {
                return ~prefixPos;
            }
            context.setParsed(ZoneId.of(prefix));
            return position;
        }
        int offset = (int) newContext.getParsed(OFFSET_SECONDS).longValue();
        ZoneOffset zoneOffset = ZoneOffset.ofTotalSeconds(offset);
        context.setParsed(ZoneId.ofOffset(prefix, zoneOffset));
        return endPos;
    } catch (DateTimeException dte) {
        return ~prefixPos;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:DateTimeFormatterBuilder.java

示例4: resolveInstantFields

import java.time.ZoneOffset; //导入方法依赖的package包/类
private void resolveInstantFields() {
    // resolve parsed instant seconds to date and time if zone available
    if (fieldValues.containsKey(INSTANT_SECONDS)) {
        if (zone != null) {
            resolveInstantFields0(zone);
        } else {
            Long offsetSecs = fieldValues.get(OFFSET_SECONDS);
            if (offsetSecs != null) {
                ZoneOffset offset = ZoneOffset.ofTotalSeconds(offsetSecs.intValue());
                resolveInstantFields0(offset);
            }
        }
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Parsed.java

示例5: with

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public ChronoZonedDateTime<D> with(TemporalField field, long newValue) {
    if (field instanceof ChronoField) {
        ChronoField f = (ChronoField) field;
        switch (f) {
            case INSTANT_SECONDS: return plus(newValue - toEpochSecond(), SECONDS);
            case OFFSET_SECONDS: {
                ZoneOffset offset = ZoneOffset.ofTotalSeconds(f.checkValidIntValue(newValue));
                return create(dateTime.toInstant(offset), zone);
            }
        }
        return ofBest(dateTime.with(field, newValue), zone, offset);
    }
    return ChronoZonedDateTimeImpl.ensureValid(getChronology(), field.adjustInto(this, newValue));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:ChronoZonedDateTimeImpl.java

示例6: queryFrom

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public ZoneOffset queryFrom(TemporalAccessor temporal) {
    if (temporal.isSupported(OFFSET_SECONDS)) {
        return ZoneOffset.ofTotalSeconds(temporal.get(OFFSET_SECONDS));
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TemporalQueries.java

示例7: decodeBinary

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public final OffsetTime decodeBinary(final BufferReader b) {
  final LocalTime time = LocalTime.ofNanoOfDay(b.readLong() * 1000);
  final ZoneOffset zone = ZoneOffset.ofTotalSeconds(-b.readInt());
  return time.atOffset(zone);
}
 
开发者ID:traneio,项目名称:ndbc,代码行数:7,代码来源:OffsetTimeEncoding.java

示例8: randomZoneOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
private ZoneOffset randomZoneOffset(final Random r) {
  return ZoneOffset.ofTotalSeconds(r.nextInt(18 * 2) + 18);
}
 
开发者ID:traneio,项目名称:ndbc,代码行数:4,代码来源:EncodingTest.java

示例9: convert

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Override
public GoogleEntry convert(Event source) {
    Objects.requireNonNull(source.getStart());
    Objects.requireNonNull(source.getEnd());

    GoogleEntry entry = new GoogleEntry();

    /*
     * TimeZone : Although Google allows different Start/End TimeZone, we
     * always assume that start/end are in the TimeZone of the startDate.
     */
    ZoneId zoneId;
    String stTimeZone = source.getStart().getTimeZone();

    if (stTimeZone == null) {
        zoneId = ZoneId.systemDefault();
    } else {
        zoneId = TimeZone.getTimeZone(stTimeZone).toZoneId();
    }

    // Start Time
    DateTime stdt = source.getStart().getDate();
    if (stdt == null) {
        stdt = source.getStart().getDateTime();
    }
    ZoneOffset stOffset = ZoneOffset.ofTotalSeconds(stdt.getTimeZoneShift() * 60);
    OffsetDateTime offsetSt = Instant.ofEpochMilli(stdt.getValue()).atOffset(stOffset);

    // End Time
    DateTime etdt = source.getEnd().getDate();
    if (etdt == null) {
        etdt = source.getEnd().getDateTime();
    }
    ZoneOffset etoffset = ZoneOffset.ofTotalSeconds(etdt.getTimeZoneShift() * 60);
    OffsetDateTime offsetEt = Instant.ofEpochMilli(etdt.getValue()).atOffset(etoffset);

    LocalDateTime startDateTime = offsetSt.toLocalDateTime();
    if (stdt.isDateOnly() || offsetEt.toLocalTime().equals(LocalTime.MIDNIGHT)) {
        offsetEt = offsetEt.minusDays(1);
        entry.setInterval(new Interval(startDateTime.toLocalDate(), startDateTime.toLocalTime(), offsetEt.toLocalDate(), LocalTime.MAX));
    } else {
        entry.setInterval(new Interval(startDateTime, offsetEt.toLocalDateTime()));
    }

    if (source.getRecurrence() != null && !source.getRecurrence().isEmpty()) {
        entry.setRecurrenceRule(source.getRecurrence().get(0));
    }

    if (source.getAttendees() != null) {
        entry.getAttendees().setAll(source.getAttendees());
    }

    if (source.getReminders() != null) {
        Event.Reminders reminders = source.getReminders();

        if (Boolean.TRUE.equals(reminders.getUseDefault())) {
            entry.setUseDefaultReminder(true);
        } else if (reminders.getOverrides() != null) {
            List<GoogleEntryReminder> entryReminders = new ArrayList<>();
            for (EventReminder reminder : reminders.getOverrides()) {
                entryReminders.add(new GoogleEntryReminder(reminder));
            }
            entry.getReminders().setAll(entryReminders);
        }
    }

    entry.setId(source.getId());
    entry.setTitle(source.getSummary());
    entry.setLocation(source.getLocation());
    entry.setZoneId(zoneId);
    entry.setFullDay(stdt.isDateOnly());
    entry.setAttendeesCanModify(source.isGuestsCanModify());
    entry.setAttendeesCanInviteOthers(source.isGuestsCanInviteOthers());
    entry.setAttendeesCanSeeOthers(source.isGuestsCanSeeOtherGuests());
    entry.setStatus(GoogleEntry.Status.fromName(source.getStatus()));
    entry.setUserObject(source);

    return entry;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:80,代码来源:EventToGoogleEntryConverter.java

示例10: test_getTotalSeconds

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test
public void test_getTotalSeconds() {
    ZoneOffset offset = ZoneOffset.ofTotalSeconds(60 * 60 + 1);
    assertEquals(offset.getTotalSeconds(), 60 * 60 + 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:6,代码来源:TCKZoneOffset.java

示例11: test_factory_ofTotalSeconds_minValue

import java.time.ZoneOffset; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void test_factory_ofTotalSeconds_minValue() {
    ZoneOffset.ofTotalSeconds(Integer.MIN_VALUE);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:5,代码来源:TCKZoneOffset.java

示例12: readOffset

import java.time.ZoneOffset; //导入方法依赖的package包/类
/**
 * Reads the state from the stream.
 *
 * @param in  the input stream, not null
 * @return the created object, not null
 * @throws IOException if an error occurs
 */
static ZoneOffset readOffset(DataInput in) throws IOException {
    int offsetByte = in.readByte();
    return (offsetByte == 127 ? ZoneOffset.ofTotalSeconds(in.readInt()) : ZoneOffset.ofTotalSeconds(offsetByte * 900));
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Ser.java


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