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


Java OffsetDateTime类代码示例

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


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

示例1: now_Clock_allSecsInDay_utc

import java.time.OffsetDateTime; //导入依赖的package包/类
@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TCKOffsetDateTime.java

示例2: convertDateInternal

import java.time.OffsetDateTime; //导入依赖的package包/类
static <T> T convertDateInternal(String string, Class<T> type, ZoneId fallbackZoneId) {
   if (java.util.Date.class.equals(type)) {
      return (T) java.util.Date.from(parseInstant(string, fallbackZoneId));
   } else if (java.sql.Date.class.equals(type)) {
      return (T) java.sql.Date.from(parseInstant(string, fallbackZoneId));
   } else if (Time.class.equals(type)) {
      return (T) Time.from(parseInstant(string, fallbackZoneId));
   } else if (Timestamp.class.equals(type)) {
      return (T) Timestamp.from(parseInstant(string, fallbackZoneId));
   } else if (LocalTime.class.equals(type)) {
      return (T) LocalTime.parse(string);
   } else if (LocalDate.class.equals(type)) {
      return (T) LocalDate.parse(string);
   } else if (LocalDateTime.class.equals(type)) {
      return (T) LocalDateTime.parse(string);
   } else if (ZonedDateTime.class.equals(type)) {
      return (T) ZonedDateTime.parse(string);
   } else if (OffsetDateTime.class.equals(type)) {
      return (T) OffsetDateTime.parse(string);
   } else if (OffsetTime.class.equals(type)) {
      return (T) OffsetTime.parse(string);
   }

   return null;
}
 
开发者ID:btc-ag,项目名称:redg,代码行数:26,代码来源:DateConverter.java

示例3: testLoad

import java.time.OffsetDateTime; //导入依赖的package包/类
@Test
public void testLoad() throws Exception {
    new ExecuteAsTimeZone(TimeZone.getTimeZone(ZoneOffset.UTC))
            .run(() -> assertThat(
                    load("2017-08-28T07:09:36.000000042Z")
                            .isEqual(OffsetDateTime.of(2017, 8, 28, 7, 9, 36, 42, ZoneOffset.UTC)),
                    is(true)
            ));
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:10,代码来源:OffsetDateTimeStringTranslatorFactoryTest.java

示例4: RichPresence

import java.time.OffsetDateTime; //导入依赖的package包/类
public RichPresence(String state, String details, OffsetDateTime startTimestamp, OffsetDateTime endTimestamp, 
        String largeImageKey, String largeImageText, String smallImageKey, String smallImageText, 
        String partyId, int partySize, int partyMax, String matchSecret, String joinSecret, 
        String spectateSecret, boolean instance)
{
    this.state = state;
    this.details = details;
    this.startTimestamp = startTimestamp;
    this.endTimestamp = endTimestamp;
    this.largeImageKey = largeImageKey;
    this.largeImageText = largeImageText;
    this.smallImageKey = smallImageKey;
    this.smallImageText = smallImageText;
    this.partyId = partyId;
    this.partySize = partySize;
    this.partyMax = partyMax;
    this.matchSecret = matchSecret;
    this.joinSecret = joinSecret;
    this.spectateSecret = spectateSecret;
    this.instance = instance;
}
 
开发者ID:jagrosh,项目名称:DiscordIPC,代码行数:22,代码来源:RichPresence.java

示例5: testZoneId

import java.time.OffsetDateTime; //导入依赖的package包/类
private void testZoneId(Locale locale, ChronoZonedDateTime<?> zdt, Calendar cal) {
    String fmtStr = "z:[%tz] z:[%1$Tz] Z:[%1$tZ] Z:[%1$TZ]";
    printFmtStr(locale, fmtStr);
    String expected = toZoneIdStr(test(fmtStr, locale, null, cal));
    test(fmtStr, locale, expected, zdt);
    // get a new cal with fixed tz
    Calendar cal0 = Calendar.getInstance();
    cal0.setTimeInMillis(zdt.toInstant().toEpochMilli());
    cal0.setTimeZone(TimeZone.getTimeZone("GMT" + zdt.getOffset().getId()));
    expected = toZoneOffsetStr(test(fmtStr, locale, null, cal0));
    if (zdt instanceof ZonedDateTime) {
        OffsetDateTime odt = ((ZonedDateTime)zdt).toOffsetDateTime();
        test(fmtStr, locale, expected, odt);
        test(fmtStr, locale, expected, odt.toOffsetTime());
    }

    // datetime + zid
    fmtStr = "c:[%tc] c:[%1$Tc]";
    printFmtStr(locale, fmtStr);
    expected = toZoneIdStr(test(fmtStr, locale, null, cal));
    test(fmtStr, locale, expected, zdt);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TestFormatter.java

示例6: test_getLong_TemporalField

import java.time.OffsetDateTime; //导入依赖的package包/类
@Test
public void test_getLong_TemporalField() {
    OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
    assertEquals(test.getLong(ChronoField.YEAR), 2008);
    assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
    assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
    assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
    assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);

    assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
    assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
    assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
    assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
    assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
    assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);

    assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
    assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TCKOffsetDateTime.java

示例7: convertObjectToJsonBytes

import java.time.OffsetDateTime; //导入依赖的package包/类
/**
 * Convert an object to JSON byte array.
 *
 * @param object
 *            the object to convert
 * @return the JSON byte array
 * @throws IOException
 */
public static byte[] convertObjectToJsonBytes(Object object)
        throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);

    JavaTimeModule module = new JavaTimeModule();
    module.addSerializer(OffsetDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(ZonedDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(LocalDateTime.class, JSR310DateTimeSerializer.INSTANCE);
    module.addSerializer(Instant.class, JSR310DateTimeSerializer.INSTANCE);
    module.addDeserializer(LocalDate.class, JSR310LocalDateDeserializer.INSTANCE);
    mapper.registerModule(module);

    return mapper.writeValueAsBytes(object);
}
 
开发者ID:ugouku,项目名称:shoucang,代码行数:24,代码来源:TestUtil.java

示例8: findADocumentByGreaterThanOrEqualMatch

import java.time.OffsetDateTime; //导入依赖的package包/类
@Test
public void findADocumentByGreaterThanOrEqualMatch() {
    searchService.index(Arrays.asList(
            new TestEntity("id1", OffsetDateTime.parse("2017-01-01T01:02:03Z")),
            new TestEntity("id2", OffsetDateTime.parse("2017-01-02T01:02:03Z")),
            new TestEntity("id3", OffsetDateTime.parse("2017-01-02T01:02:04Z")),
            new TestEntity("id4", OffsetDateTime.parse("2017-01-03T01:02:03Z"))
    ));

    Query<TestEntity> query = searchService.createQuery(TestEntity.class)
            .filter("value", GREATER_THAN_OR_EQUAL, OffsetDateTime.parse("2017-01-02T01:02:03Z"))
            .build();

    assertThat(searchService.execute(query))
            .extractingResultOf("getId")
            .containsExactlyInAnyOrder("id2", "id3", "id4");
}
 
开发者ID:n15g,项目名称:spring-boot-gae,代码行数:18,代码来源:OffsetDateTimeSearchIntegrationTest.java

示例9: dispatchEvent

import java.time.OffsetDateTime; //导入依赖的package包/类
@Override
public void dispatchEvent(JSONObject json, int sequence) {
    String msg_id = json.getString("id");
    String channel_id = json.getString("channel_id");

    MessageChannel channel = (MessageChannel) identity.getMessageChannel(channel_id);
    if (channel != null) {

        if (channel.isPrivate()) {
            dispatchEvent(new PrivateMessageDeleteEvent(identity, sequence, channel, msg_id, OffsetDateTime.from(Instant.now())));
        } else {
            dispatchEvent(new GuildMessageDeleteEvent(identity, sequence, channel, msg_id, OffsetDateTime.from(Instant.now())));
        }

    } else {
        logger.log(LogLevel.FETAL, "[UNKNOWN CHANNEL][MESSAGE_DELETE_EVENT]");
    }
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:19,代码来源:MessageDeleteEventHandler.java

示例10: dispatchEvent

import java.time.OffsetDateTime; //导入依赖的package包/类
@Override
public void dispatchEvent(JSONObject json, int sequence) {
    Channel channel = (Channel) identity.getChannel(json.getString("id"));
    OffsetDateTime timeStamp = OffsetDateTime.now();

    if (channel.isType(IChannel.Type.GROUP_DM)) {
        identity.getClient().removeGroup(channel.getId());
        dispatchEvent(new GroupDeleteEvent(identity, sequence, channel, timeStamp));
    } else if (channel.isType(IChannel.Type.DM)) {
        identity.removePrivateChannel(channel.getId());
        dispatchEvent(new PrivateChannelDeleteEvent(identity, sequence, channel, timeStamp));
    } else {
        Guild guild = (Guild) ((IGuildChannel) channel).getGuild();
        if (channel.isType(IChannel.Type.GUILD_TEXT)) {
            guild.removeTextChannel(channel.getId());
            dispatchEvent(new TextChannelDeleteEvent(identity, sequence, channel, timeStamp, guild));
        } else {
            guild.removeVoiceChannel(channel.getId());
            dispatchEvent(new VoiceChannelDeleteEvent(identity, sequence, channel, timeStamp, guild));
        }
    }
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:23,代码来源:ChannelDeleteEventHandler.java

示例11: MPD

import java.time.OffsetDateTime; //导入依赖的package包/类
private MPD(List<ProgramInformation> programInformations, List<BaseURL> baseURLs, List<String> locations, List<Period> periods, List<Metrics> metrics, List<Descriptor> essentialProperties, List<Descriptor> supplementalProperties, List<UTCTiming> utcTimings, String id, Profiles profiles, PresentationType type, OffsetDateTime availabilityStartTime, OffsetDateTime availabilityEndTime, OffsetDateTime publishTime, Duration mediaPresentationDuration, Duration minimumUpdatePeriod, Duration minBufferTime, Duration timeShiftBufferDepth, Duration suggestedPresentationDelay, Duration maxSegmentDuration, Duration maxSubsegmentDuration, String schemaLocation) {
    this.programInformations = programInformations;
    this.baseURLs = baseURLs;
    this.locations = locations;
    this.periods = periods;
    this.metrics = metrics;
    this.essentialProperties = essentialProperties;
    this.supplementalProperties = supplementalProperties;
    this.utcTimings = utcTimings;
    this.id = id;
    this.profiles = profiles;
    this.type = type;
    this.availabilityStartTime = availabilityStartTime;
    this.availabilityEndTime = availabilityEndTime;
    this.publishTime = publishTime;
    this.mediaPresentationDuration = mediaPresentationDuration;
    this.minimumUpdatePeriod = minimumUpdatePeriod;
    this.minBufferTime = minBufferTime;
    this.timeShiftBufferDepth = timeShiftBufferDepth;
    this.suggestedPresentationDelay = suggestedPresentationDelay;
    this.maxSegmentDuration = maxSegmentDuration;
    this.maxSubsegmentDuration = maxSubsegmentDuration;
    this.schemaLocation = schemaLocation;
}
 
开发者ID:carlanton,项目名称:mpd-tools,代码行数:25,代码来源:MPD.java

示例12: data_adjustInto

import java.time.OffsetDateTime; //导入依赖的package包/类
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TCKOffsetTime.java

示例13: doTest_factory_ofInstant_all

import java.time.OffsetDateTime; //导入依赖的package包/类
private void doTest_factory_ofInstant_all(long minYear, long maxYear) {
    long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
    int minOffset = (minYear <= 0 ? 0 : 3);
    int maxOffset = (maxYear <= 0 ? 0 : 3);
    long minDays = (minYear * 365L + ((minYear + minOffset) / 4L - (minYear + minOffset) / 100L + (minYear + minOffset) / 400L)) - days_0000_to_1970;
    long maxDays = (maxYear * 365L + ((maxYear + maxOffset) / 4L - (maxYear + maxOffset) / 100L + (maxYear + maxOffset) / 400L)) + 365L - days_0000_to_1970;

    final LocalDate maxDate = LocalDate.of(Year.MAX_VALUE, 12, 31);
    OffsetDateTime expected = OffsetDateTime.of(LocalDate.of((int) minYear, 1, 1), LocalTime.of(0, 0, 0, 0), ZoneOffset.UTC);
    for (long i = minDays; i < maxDays; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        try {
            OffsetDateTime test = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
            assertEquals(test, expected);
            if (expected.toLocalDate().equals(maxDate) == false) {
                expected = expected.plusDays(1);
            }
        } catch (RuntimeException|Error ex) {
            System.out.println("Error: " + i + " " + expected);
            throw ex;
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:TestOffsetDateTime_instants.java

示例14: now_Clock_allSecsInDay_offset

import java.time.OffsetDateTime; //导入依赖的package包/类
@Test
public void now_Clock_allSecsInDay_offset() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant.minusSeconds(OFFSET_PONE.getTotalSeconds()), OFFSET_PONE);
        OffsetDateTime test = OffsetDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60) ? 1 : 2);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), OFFSET_PONE);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TCKOffsetDateTime.java

示例15: LocalTime

import java.time.OffsetDateTime; //导入依赖的package包/类
public LocalTime(OffsetDateTime offsetDateTime, Locale locale) {
    offset = offsetDateTime.getOffset().getTotalSeconds();
    year = offsetDateTime.getYear();
    month = offsetDateTime.getMonth().getDisplayName(TextStyle.FULL,locale);
    dayOfMonth = offsetDateTime.getDayOfMonth();
    dayOfWeek = offsetDateTime.getDayOfWeek().getDisplayName(TextStyle.FULL,locale);
    monthValue = offsetDateTime.getMonthValue();
    hour = offsetDateTime.getHour();
    minute = offsetDateTime.getMinute();
    second = offsetDateTime.getSecond();
    nano = offsetDateTime.getNano();
}
 
开发者ID:graphhopper,项目名称:timezone,代码行数:13,代码来源:LocalTime.java


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