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


Java LocalDate.getMonthValue方法代碼示例

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


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

示例1: main

import java.time.LocalDate; //導入方法依賴的package包/類
public static void main(String[] args) {
    /* Read and save input as LocalDates */
    Scanner scan = new Scanner(System.in);
    LocalDate returnDate = readDate(scan);
    LocalDate expectDate = readDate(scan);
    scan.close();
    
    /* Calculate fine */
    int fine;
    if (returnDate.isEqual(expectDate) || returnDate.isBefore(expectDate)) {
        fine = 0;
    } else if (returnDate.getMonth() == expectDate.getMonth() && returnDate.getYear() == expectDate.getYear()) {
        fine = 15 * (returnDate.getDayOfMonth() - expectDate.getDayOfMonth());
    } else if (returnDate.getYear() == expectDate.getYear()) {
        fine = 500 * (returnDate.getMonthValue() - expectDate.getMonthValue());
    } else {
        fine = 10000;
    }
    System.out.println(fine);
}
 
開發者ID:MohamedSondo,項目名稱:ACE_HackerRank,代碼行數:21,代碼來源:Solution.java

示例2: calcDiasTrabUltimoMes

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Calcula o total de dias trabalhos no último mês
 *  
 * @param dataSaida Referente ao último dia trabalhado do funcionário.
 * @return O total de dias trabalhados no último mês.
 */
public int calcDiasTrabUltimoMes(LocalDate dataSaida) {
    int totDiasTrabUltMes = 0;

    int mesFim = dataSaida.getMonthValue();
    int anoFim = dataSaida.getYear();
    LocalDate primeiroDiaMes = LocalDate.of(anoFim, mesFim, 1);
    totDiasTrabUltMes = calcDiferDias(primeiroDiaMes, dataSaida);

    /*		Acrescento mais um dia na váriavel, isto é aplicado para que a contagem
     * 		de dias fique correta.  Por exemplo: Se funcionário trabalhou do dia 01
     * 		até o dia 05, o totalDiasTrabalhados seria de 04 dias, sendo o correto
     *		seriam 05 (Dia 01, Dia 02, Dia 03, Dia 04 e Dia 05)*/
    totDiasTrabUltMes += 1;

    return totDiasTrabUltMes;

}
 
開發者ID:tglima,項目名稱:CRS,代碼行數:24,代碼來源:CalcPeriodos.java

示例3: test_parse_resolve_localizedWom_lenient

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(MONTH_OF_YEAR).appendLiteral(':')
                .appendValue(womField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(LENIENT);
        int wom = date.get(womField);
        int dow = date.get(DAY_OF_WEEK);
        for (int j = wom - 10; j < wom + 10; j++) {
            String str = date.getYear() + ":" + date.getMonthValue() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - wom), " ::" + str + ": :" + i + "::" + j);
        }

        date = date.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TCKWeekFields.java

示例4: test_parse_resolve_localizedWomDow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(MONTH_OF_YEAR).appendLiteral(':')
                .appendValue(womField).appendLiteral(':')
                .appendValue(dowField).toFormatter();
        String str = date.getYear() + ":" + date.getMonthValue() + ":" +
                date.get(womField) + ":" + date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TCKWeekFields.java

示例5: showPerson

import java.time.LocalDate; //導入方法依賴的package包/類
@FXML
public void showPerson(Person person) {
    if (person == null) {
        firstNameLabel.setText("");
        lastNameLabel.setText("");
        cityLabel.setText("");
        birthdateLabel.setText("");
    } else {
        firstNameLabel.setText(person.getFirstName().getValue());
        lastNameLabel.setText(person.getLastName().getValue());
        cityLabel.setText(person.getLastName().getValue());
        LocalDate date = (LocalDate)person.getBithdate().getValue();
        String strDate = date.getDayOfMonth() +"."+date.getMonthValue()+"."+date.getYear();
        birthdateLabel.setText(strDate);
    }
}
 
開發者ID:biblelamp,項目名稱:QAExercises,代碼行數:17,代碼來源:PersonsController.java

示例6: test_parse_resolve_localizedWom

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWom(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(MONTH_OF_YEAR).appendLiteral(':')
                .appendValue(womField).appendLiteral(':')
                .appendValue(DAY_OF_WEEK).toFormatter().withResolverStyle(SMART);
        String str = date.getYear() + ":" + date.getMonthValue() + ":" +
                date.get(womField) + ":" + date.get(DAY_OF_WEEK);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " ::" + str + "::" + i);

        date = date.plusDays(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:TCKWeekFields.java

示例7: test_date_parse

import java.time.LocalDate; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_parse(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
    DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
    Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
    TemporalAccessor parsed = f.parse(text, pos);
    assertEquals(pos.getIndex(), text.length());
    assertEquals(pos.getErrorIndex(), -1);
    assertEquals(LocalDate.from(parsed), date);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TCKLocalizedPrinterParser.java

示例8: test_date_print

import java.time.LocalDate; //導入方法依賴的package包/類
@SuppressWarnings("deprecation")
@Test(dataProvider="date")
public void test_date_print(LocalDate date, FormatStyle dateStyle, int dateStyleOld, Locale locale) {
    DateFormat old = DateFormat.getDateInstance(dateStyleOld, locale);
    Date oldDate = new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
    String text = old.format(oldDate);

    DateTimeFormatter f = builder.appendLocalized(dateStyle, null).toFormatter(locale);
    String formatted = f.format(date);
    assertEquals(formatted, text);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:12,代碼來源:TCKLocalizedPrinterParser.java

示例9: GetLocalDate

import java.time.LocalDate; //導入方法依賴的package包/類
private static DateObjects GetLocalDate() {
    final Date date = new Date();
    final LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
    final int year = localDate.getYear();
    final int month = localDate.getMonthValue();
    final int day = localDate.getDayOfMonth();

    return new DateObjects(year, month, day);

}
 
開發者ID:PanagiotisDrakatos,項目名稱:Weather-Forecast,代碼行數:11,代碼來源:LocationInfo.java

示例10: makeAccount

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Factory method for creating Account instance.
 * @param user account user.
 * @return reference to new Account instance.
 */
public static Account makeAccount(User user) {
    Account result;
    if (user != null && user.getName() != null && user.getPassport() != null) {
        LocalDate validThruTo = LocalDate.now().plusYears(3);
        result = new Account(validThruTo.getMonthValue(), validThruTo.getYear(), user.getPassport().getFirstName(), user.getPassport().getLastName(), nextNumber--);
    } else {
        result = new Account(0, 0, "not valid name", "not valid name", 0);
    }
    return result;
}
 
開發者ID:PavelZubaha,項目名稱:pzubaha,代碼行數:16,代碼來源:Bank.java

示例11: fileMethod

import java.time.LocalDate; //導入方法依賴的package包/類
public static void fileMethod(File file) {
        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String jsonString = "";
            String tempString;
            while ((tempString = bufferedReader.readLine()) != null) {
                jsonString += tempString;
            }
            bufferedReader.close();
            jsonString = Unicode2utf8Utils.convert(jsonString).replaceAll("<.*?>", "");
            Map map = JSON.parseObject(jsonString);
            if (map.get("created_at") == null) {
                if (map.get("date") == null){
                    System.out.println(cnt++ + " error files.");
                    file.delete();
                }
                return;
            }
            String created_at = (String) map.get("created_at");
            String date;
            Pattern patternA = Pattern.compile("\\d+-\\d+-\\d+");
            Pattern patternB = Pattern.compile("\\d+-\\d+");
            Pattern patternC = Pattern.compile("\\d{1,2}:\\d{1,2}");
            if (patternA.matcher(created_at).find()) {
                date = created_at.substring(0, 10);
            } else if (patternB.matcher(created_at).find()) {
                date = "2017-" + created_at.substring(0, 5);
            } else if (patternC.matcher(created_at).find()) {
                LocalDate localDate = LocalDate.now();
                date = localDate.getYear() + "-" + localDate.getMonthValue() + "-" + localDate.getDayOfMonth();
            } else {
                file.delete();
                System.out.println(cnt++ + " error files.");
                return;
            }
            map.put("date", date);
            map.remove("created_at");
            map.remove("thumbnail_pic");
            map.remove("bmiddle_pic");
            map.remove("original_pic");
            map.remove("itemid");
            map.remove("status");
            map.remove("rid");
            map.remove("cardid");
            map.remove("visible");
            if (map.get("pics") != null) {
                List list = (List) map.get("pics");
                map.put("pics", list.size());
            } else {
                map.put("pics", 0);
            }
            if (map.get("user") != null) {
                Map userMap = (Map) map.get("user");
                userMap.remove("profile_image_url");
                userMap.remove("cover_image_phone");
                userMap.remove("profile_url");
                userMap.remove("description");
                userMap.remove("follow_me");
                userMap.remove("following");
            }
            PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(file)));
            printWriter.print(com.alibaba.fastjson.JSON.toJSONString(map));
            printWriter.close();
        } catch (Exception e) {
            file.delete();
            System.out.println(cnt++ + " error files.");
//            e.printStackTrace();
        }
    }
 
開發者ID:CieloSun,項目名稱:FashionSpider,代碼行數:70,代碼來源:TidyWeboData.java

示例12: isEqual

import java.time.LocalDate; //導入方法依賴的package包/類
private static boolean isEqual(LocalDate ld, java.sql.Date d) {
    return ld.getYear() == d.getYear() + 1900 &&
           ld.getMonthValue() == d.getMonth() + 1 &&
           ld.getDayOfMonth() == d.getDate();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:6,代碼來源:JavatimeTest.java

示例13: localDateToDateValue

import java.time.LocalDate; //導入方法依賴的package包/類
static DateValue localDateToDateValue(LocalDate date) {
    return new DateValueImpl(date.getYear(), date.getMonthValue(),
            date.getDayOfMonth());
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:5,代碼來源:LocalDateIteratorFactory.java

示例14: valueOf

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Obtains an instance of {@code Date} from a {@link LocalDate} object
 * with the same year, month and day of month value as the given
 * {@code LocalDate}.
 * <p>
 * The provided {@code LocalDate} is interpreted as the local date
 * in the local time zone.
 *
 * @param date a {@code LocalDate} to convert
 * @return a {@code Date} object
 * @exception NullPointerException if {@code date} is null
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Date valueOf(LocalDate date) {
    return new Date(date.getYear() - 1900, date.getMonthValue() -1,
                    date.getDayOfMonth());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:Date.java


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