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


Java LocalDateTime.of方法代码示例

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


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

示例1: createTransition

import java.time.LocalDateTime; //导入方法依赖的package包/类
/**
 * Creates a transition instance for the specified year.
 * <p>
 * Calculations are performed using the ISO-8601 chronology.
 *
 * @param year  the year to create a transition for, not null
 * @return the transition instance, not null
 */
public ZoneOffsetTransition createTransition(int year) {
    LocalDate date;
    if (dom < 0) {
        date = LocalDate.of(year, month, month.length(IsoChronology.INSTANCE.isLeapYear(year)) + 1 + dom);
        if (dow != null) {
            date = date.with(previousOrSame(dow));
        }
    } else {
        date = LocalDate.of(year, month, dom);
        if (dow != null) {
            date = date.with(nextOrSame(dow));
        }
    }
    if (timeEndOfDay) {
        date = date.plusDays(1);
    }
    LocalDateTime localDT = LocalDateTime.of(date, time);
    LocalDateTime transition = timeDefinition.createDateTime(localDT, standardOffset, offsetBefore);
    return new ZoneOffsetTransition(transition, offsetBefore, offsetAfter);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:ZoneOffsetTransitionRule.java

示例2: test_get_TemporalField

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_get_TemporalField() {
    LocalDateTime test = LocalDateTime.of(2008, 6, 30, 12, 30, 40, 987654321);
    assertEquals(test.get(ChronoField.YEAR), 2008);
    assertEquals(test.get(ChronoField.MONTH_OF_YEAR), 6);
    assertEquals(test.get(ChronoField.DAY_OF_MONTH), 30);
    assertEquals(test.get(ChronoField.DAY_OF_WEEK), 1);
    assertEquals(test.get(ChronoField.DAY_OF_YEAR), 182);

    assertEquals(test.get(ChronoField.HOUR_OF_DAY), 12);
    assertEquals(test.get(ChronoField.MINUTE_OF_HOUR), 30);
    assertEquals(test.get(ChronoField.SECOND_OF_MINUTE), 40);
    assertEquals(test.get(ChronoField.NANO_OF_SECOND), 987654321);
    assertEquals(test.get(ChronoField.HOUR_OF_AMPM), 0);
    assertEquals(test.get(ChronoField.AMPM_OF_DAY), 1);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:TCKLocalDateTime.java

示例3: checkDateTime

import java.time.LocalDateTime; //导入方法依赖的package包/类
public boolean checkDateTime(){ /// not working...?
    LocalDateTime currentDateTime = LocalDateTime.now();
       // DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss");
       // String nowDate = currentDateTime.format(formatter);
      
        String[] datarrayString = date.split("-");
        String[] timeendarray = "23:59:59".split(":");
        
        
        LocalDateTime pickedTimeEnd = LocalDateTime.of(Integer.parseInt(datarrayString[0]),Integer.parseInt(datarrayString[1]),Integer.parseInt(datarrayString[2]), Integer.parseInt(timeendarray[0]), Integer.parseInt(timeendarray[1]), Integer.parseInt(timeendarray[2]));
              
        if(pickedTimeEnd.isBefore(currentDateTime)){
            return false;
        }
        //else if(pickedTimeEnd.isBefore(currentDateTime)){
            
          //  return false;
        //}
        else{
            System.out.print(pickedTimeEnd +"  "+currentDateTime);
            return true;
        }

}
 
开发者ID:karanjadhav2508,项目名称:kqsse17,代码行数:25,代码来源:Quiz.java

示例4: test_withZoneSameLocal_retainOffset2

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_withZoneSameLocal_retainOffset2() {
    LocalDateTime ldt = LocalDateTime.of(2008, 11, 2, 1, 30, 59, 0);  // overlap
    ZonedDateTime base = ZonedDateTime.of(ldt, ZoneId.of("UTC-05:00") );
    ZonedDateTime test = base.withZoneSameLocal(ZoneId.of("America/New_York"));
    assertEquals(base.getOffset(), ZoneOffset.ofHours(-5));
    assertEquals(test.getOffset(), ZoneOffset.ofHours(-5));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TCKZonedDateTime.java

示例5: factory_ofEpochSecond_longOffset_beforeEpoch

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void factory_ofEpochSecond_longOffset_beforeEpoch() {
    LocalDateTime base = LocalDateTime.of(1970, 1, 1, 2, 0, 0, 500);
    for (int i = 0; i < 100000; i++) {
        LocalDateTime test = LocalDateTime.ofEpochSecond(-i, 500, OFFSET_PTWO);
        assertEquals(test, base.minusSeconds(i));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:9,代码来源:TCKLocalDateTime.java

示例6: data_fieldAndAccessor

import java.time.LocalDateTime; //导入方法依赖的package包/类
@DataProvider(name="fieldAndAccessor")
Object[][] data_fieldAndAccessor() {
    return new Object[][] {
            {YEAR, LocalDate.of(2000, 2, 29), true, 2000},
            {YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2000},
            {MONTH_OF_YEAR, LocalDate.of(2000, 2, 29), true, 2},
            {MONTH_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 2},
            {DAY_OF_MONTH, LocalDate.of(2000, 2, 29), true, 29},
            {DAY_OF_MONTH, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 29},
            {DAY_OF_YEAR, LocalDate.of(2000, 2, 29), true, 60},
            {DAY_OF_YEAR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 60},

            {HOUR_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5},
            {HOUR_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5},

            {MINUTE_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*60 + 4},
            {MINUTE_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*60 + 4},
            {MINUTE_OF_HOUR, LocalTime.of(5, 4, 3, 200), true, 4},
            {MINUTE_OF_HOUR, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 4},

            {SECOND_OF_DAY, LocalTime.of(5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
            {SECOND_OF_DAY, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 5*3600 + 4*60 + 3},
            {SECOND_OF_MINUTE, LocalTime.of(5, 4, 3, 200), true, 3},
            {SECOND_OF_MINUTE, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 3},

            {NANO_OF_SECOND, LocalTime.of(5, 4, 3, 200), true, 200},
            {NANO_OF_SECOND, LocalDateTime.of(2000, 2, 29, 5, 4, 3, 200), true, 200},

            {YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {MONTH_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {DAY_OF_MONTH, LocalTime.of(5, 4, 3, 200), false, -1},
            {DAY_OF_YEAR, LocalTime.of(5, 4, 3, 200), false, -1},
            {HOUR_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {MINUTE_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {MINUTE_OF_HOUR, LocalDate.of(2000, 2, 29), false, -1},
            {SECOND_OF_DAY, LocalDate.of(2000, 2, 29), false, -1},
            {SECOND_OF_MINUTE, LocalDate.of(2000, 2, 29), false, -1},
            {NANO_OF_SECOND, LocalDate.of(2000, 2, 29), false, -1},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:41,代码来源:TCKChronoField.java

示例7: test_minusMinutes_minutes

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_minusMinutes_minutes() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.minusMinutes(30);
    assertEquals(test, ZonedDateTime.of(ldt.minusMinutes(30), ZONE_0100));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TCKZonedDateTime.java

示例8: parseLineToInfo

import java.time.LocalDateTime; //导入方法依赖的package包/类
private InfoSchema parseLineToInfo(String line, LocalDate localDate) {
    String[] columns = line.split(" \\| ");
    Matcher matcher = mjlogPattern.matcher(columns[3]);
    if (matcher.find()) {
        String id = matcher.group(1);
        if (this.databaseService.existsIdInINFO(id)) return null;

        boolean isSanma = columns[2].substring(0, 1).equals("三");
        boolean isTonnan = columns[2].substring(2, 3).equals("南");
        int minute = Integer.parseInt(columns[1]);
        String[] playerAndScore = columns[4].split(" ");
        String[] players = new String[4];
        int[] scores = new int[4];
        for (int i = 0; i < playerAndScore.length; i++) {
            Matcher playerMatcher = playerPattern.matcher(playerAndScore[i]);
            if (playerMatcher.find()) {
                players[i] = playerMatcher.group(1);
                scores[i] = (int) Float.parseFloat(playerMatcher.group(2));
            }
        }
        LocalTime localTime = LocalTime.from(DateTimeFormatter.ofPattern("HH:mm").parse(columns[0]));
        LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
        return new InfoSchema.Builder(id, isSanma, isTonnan, localDateTime,
                players[0], players[1], players[2], players[3])
                .minute(minute)
                .firstScore(scores[0])
                .secondScore(scores[1])
                .thirdScore(scores[2])
                .fourthScore(scores[3])
                .build();
    }

    return null;
}
 
开发者ID:CrazyBBB,项目名称:tenhou-visualizer,代码行数:35,代码来源:DownloadService.java

示例9: testScalarInput

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void testScalarInput() throws Exception {
    LocalDateTime ttl = LocalDateTime.of(2017, 1, 31, 10, 9, 48);
    String queryString = Generated.mutation(mutation -> mutation
        .setInteger(new Generated.SetIntegerInput("answer", 42).setTtl(ttl))
    ).toString();
    assertEquals("mutation{set_integer(input:{key:\"answer\",value:42,ttl:\"2017-01-31T10:09:48\"})}", queryString);
}
 
开发者ID:Shopify,项目名称:graphql_java_gen,代码行数:9,代码来源:IntegrationTest.java

示例10: main

import java.time.LocalDateTime; //导入方法依赖的package包/类
public static void main(String[] args) {
    int hours;
    LocalDateTime now = LocalDateTime.of(220, 10, 01, 0, 0);
    LocalDate before = now.toLocalDate().minusDays(1);
    LocalTime after = now.toLocalTime().plusHours(1);

    /*while (before.isBefore(after) && hours < 4) {
        ++hours;
    }*/

}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:12,代码来源:Camera.java

示例11: test_plusMonths_zero

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test
public void test_plusMonths_zero() {
    LocalDateTime ldt = LocalDateTime.of(2008, 6, 30, 23, 30, 59, 0);
    ZonedDateTime base = ZonedDateTime.of(ldt, ZONE_0100);
    ZonedDateTime test = base.plusMonths(0);
    assertEquals(test, base);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:TCKZonedDateTime.java

示例12: factory_of_6intsMonth_secondTooLow

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_6intsMonth_secondTooLow() {
    LocalDateTime.of(2007, Month.JULY, 15, 12, 30, -1, 987654321);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:TCKLocalDateTime.java

示例13: test_equals_false_day_differs

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(dataProvider="sampleDateTimes")
public void test_equals_false_day_differs(int y, int m, int d, int h, int mi, int s, int n) {
    LocalDateTime a = LocalDateTime.of(y, m, d, h, mi, s, n);
    LocalDateTime b = LocalDateTime.of(y, m, d + 1, h, mi, s, n);
    assertFalse(a.equals(b));
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:7,代码来源:TCKLocalDateTime.java

示例14: factory_of_7ints_minuteTooHigh

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_minuteTooHigh() {
    LocalDateTime.of(2007, 7, 15, 12, 60, 40, 987654321);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:TCKLocalDateTime.java

示例15: factory_of_7ints_dayTooHigh

import java.time.LocalDateTime; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_7ints_dayTooHigh() {
    LocalDateTime.of(2007, 7, 32, 12, 30, 40, 987654321);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:TCKLocalDateTime.java


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