當前位置: 首頁>>代碼示例>>Java>>正文


Java Period.ofWeeks方法代碼示例

本文整理匯總了Java中java.time.Period.ofWeeks方法的典型用法代碼示例。如果您正苦於以下問題:Java Period.ofWeeks方法的具體用法?Java Period.ofWeeks怎麽用?Java Period.ofWeeks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.Period的用法示例。


在下文中一共展示了Period.ofWeeks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: apply

import java.time.Period; //導入方法依賴的package包/類
@Override
public final Period apply(String value) {
    try {
        if (getNullChecker().applyAsBoolean(value)) {
            return null;
        } else {
            final Matcher matcher = pattern.matcher(value);
            if (matcher.matches()) {
                final int digits = Integer.parseInt(matcher.group(1));
                final char code = matcher.group(2).toUpperCase().charAt(0);
                switch (code) {
                    case 'D':   return Period.ofDays(digits);
                    case 'W':   return Period.ofWeeks(digits);
                    case 'M':   return Period.ofMonths(digits);
                    case 'Y':   return Period.ofYears(digits);
                    default:    throw new IllegalArgumentException("Unsupported period type: " + code);
                }
            } else {
                throw new IllegalArgumentException("Cannot parse value into an Period: " + value + " pattern: " + pattern.pattern());
            }
        }
    } catch (Exception ex) {
        throw new FormatException("Failed to parse value into Period: " + value, ex);
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:26,代碼來源:ParserOfPeriod.java

示例2: singleRule

import java.time.Period; //導入方法依賴的package包/類
@Test
public void singleRule() {
    final Builder<RuleSetBuilder, DecisionTreeRuleSet> ruleSetBuilder = ruleSetBuilder();
    final Instant now = Instant.now();
    final Period period = Period.ofWeeks(4);

    CommisionRuleSetSupplier.addRule(ruleSetBuilder, "*", "CME", "*", "*", "INDEX", now.minus(period),
            now.plus(period), 1L, "1.1");
    final DecisionTreeRuleSet ruleSet = ruleSetBuilder.build();
    final TreeNode node = constructTree(ruleSet);
    Assert.assertNotNull(node);

    checkMatch(inputC, now, node, 1L);

    checkNoMatch(inputC, now.plus(Period.ofWeeks(8)), node);
    checkNoMatch(inputC, now.minus(Period.ofWeeks(8)), node);

    checkMatch(inputC, now.plus(Period.ofDays(2)), node, 1L);

    checkNoMatch(inputA, now, node);
    checkNoMatch(inputB, now, node);
    checkNoMatch(inputD, now, node);
    checkNoMatch(inputE, now, node);
    checkNoMatch(inputF, now, node);
}
 
開發者ID:jpmorganchase,項目名稱:swblocks-decisiontree,代碼行數:26,代碼來源:DatedEvaluatorTest.java

示例3: main

import java.time.Period; //導入方法依賴的package包/類
public static void main(String[] args) {
    Period period = Period.of(1, 2, 7);
    Period period2 = Period.ofYears(2);
    Period period3 = Period.ofMonths(5);
    Period period4 = Period.ofWeeks(10);
    Period period5 = Period.ofDays(15);

    Period period6 = Period.ofDays(15);

    Period p5Yrs1 = Period.parse("P5y");
    Period p5Yrs2 = Period.parse("p5y");
    Period p5Yrs3 = Period.parse("P5Y");
    Period p5Yrs4 = Period.parse("+P5Y");
    Period p5Yrs5 = Period.parse("P+5Y");
    Period p5Yrs6 = Period.parse("-P-5Y");

    System.out.printf("%s : %s", p5Yrs1, p5Yrs2);
    System.out.println();
    System.out.printf("-P-5Y: %s", p5Yrs6);
    System.out.println();

    Period p5Yrs7 = Period.parse("P5y1m2d");
    Period p5Yrs8 = Period.parse("p9m");
    Period p5Yrs9 = Period.parse("P60d");

    // For the string form PnW, the count of weeks is multiplied by 7 to
    // get the number of days
    Period p5Yrs10 = Period.parse("-P5Y5W");

    System.out.printf("p5Yrs7: %s,  p5Yrs8: %s, p5Yrs9: %s, p5Yrs10: %s",
            p5Yrs7,
            p5Yrs8,
            p5Yrs9,
            p5Yrs10);
    System.out.println();

    // static method between
    LocalDate carnivalStart = LocalDate.of(2050, 12, 31);
    LocalDate carnivalEnd = LocalDate.of(2051, 1, 2);

    // period = endDate - startDate
    Period periodBetween = Period.between(carnivalEnd, carnivalStart);
    System.out.println(periodBetween );

}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:46,代碼來源:Main.java


注:本文中的java.time.Period.ofWeeks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。