当前位置: 首页>>代码示例>>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;未经允许,请勿转载。