本文整理汇总了Java中java.time.LocalDate.ofYearDay方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.ofYearDay方法的具体用法?Java LocalDate.ofYearDay怎么用?Java LocalDate.ofYearDay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalDate
的用法示例。
在下文中一共展示了LocalDate.ofYearDay方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* 程序执行入口.
*
* @param args 命令行参数
*/
public static void main(String[] args) {
LocalDate today = LocalDate.now(); // |\longremark{获取当前日期}|
System.out.println("Current Date=" + today);
LocalDate firstDay2016 = LocalDate.of(2016, 1, 1); // |\longremark{给定年月日创建特定日期对象}|
System.out.println("Specific Date=" + firstDay2016);
//LocalDate feb29_2014 = LocalDate.of(2014, Month.FEBRUARY, 29); // |\longremark{给定日期不合法}|
//Current date in "Asia/Shanghai", you can get it from ZoneId javadoc
LocalDate todayShanghai = LocalDate.now(ZoneId.of("Asia/Shanghai")); // |\longremark{根据时区获取当前日期}|
System.out.println("Current Date in CST=" + todayShanghai);
//LocalDate todayIST = LocalDate.now(ZoneId.of("IST")); // |\longremark{给定时区不合法}|
LocalDate dateFromBase = LocalDate.ofEpochDay(365); // |\longremark{从1970-1-1开始计算}|
System.out.println("365th day from base date= " + dateFromBase);
LocalDate hundredDay2016 = LocalDate.ofYearDay(2016, 100); // |\longremark{从给定年份开始计算}|
System.out.println("100th day of 2016=" + hundredDay2016);
LocalDate one = LocalDate.parse("2016-11-21"); //|\longremark{将字符串解析为LocalDate对象}|
LocalDate two = LocalDate.parse("2016-11-22");
System.out.println("2016-11-21 parsed to LocalDate = " + one);
System.out.println("2016-11-21 < 2016-11-22 ? " + one.isBefore(two));
System.out.println("2016-11-21 < 2016-11-21 ? " + one.isBefore(one));
System.out.println("2016-11-22 > 2016-11-21 ? " + two.isAfter(one));
}
示例2: second
import java.time.LocalDate; //导入方法依赖的package包/类
public static Time second(int seconds) {
LocalDate date = LocalDate.ofYearDay(0, asStartDays(seconds));
LocalTime time = LocalTime.ofSecondOfDay(asSecondsAtDay(seconds));
return new Time(LocalDateTime.of(date, time));
}
示例3: factory_ofYearDay_ints_yearTooLow
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofYearDay_ints_yearTooLow() {
LocalDate.ofYearDay(Integer.MIN_VALUE, 1);
}
示例4: factory_ofYearDay_ints_dayTooHigh
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofYearDay_ints_dayTooHigh() {
LocalDate.ofYearDay(2007, 367);
}
示例5: factory_ofYearDay_ints_366nonLeap
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofYearDay_ints_366nonLeap() {
LocalDate.ofYearDay(2007, 366);
}
示例6: factory_ofYearDay_ints_dayTooLow
import java.time.LocalDate; //导入方法依赖的package包/类
@Test(expectedExceptions=DateTimeException.class)
public void factory_ofYearDay_ints_dayTooLow() {
LocalDate.ofYearDay(2007, 0);
}
示例7: dateYearDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains an ISO local date from the proleptic-year and day-of-year fields.
* <p>
* This is equivalent to {@link LocalDate#ofYearDay(int, int)}.
*
* @param prolepticYear the ISO proleptic-year
* @param dayOfYear the ISO day-of-year
* @return the ISO local date, not null
* @throws DateTimeException if unable to create the date
*/
@Override
// override with covariant return type
public LocalDate dateYearDay(int prolepticYear, int dayOfYear) {
return LocalDate.ofYearDay(prolepticYear, dayOfYear);
}
示例8: dateYearDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains an ISO local date from the proleptic-year and day-of-year fields.
* <p>
* This is equivalent to {@link LocalDate#ofYearDay(int, int)}.
*
* @param prolepticYear the ISO proleptic-year
* @param dayOfYear the ISO day-of-year
* @return the ISO local date, not null
* @throws DateTimeException if unable to create the date
*/
@Override // override with covariant return type
public LocalDate dateYearDay(int prolepticYear, int dayOfYear) {
return LocalDate.ofYearDay(prolepticYear, dayOfYear);
}
示例9: dateYearDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains a local date in Japanese calendar system from the
* proleptic-year and day-of-year fields.
* <p>
* The day-of-year in this factory is expressed relative to the start of the proleptic year.
* The Japanese proleptic year and day-of-year are the same as those in the ISO calendar system.
* They are not reset when the era changes.
*
* @param prolepticYear the proleptic-year
* @param dayOfYear the day-of-year
* @return the Japanese local date, not null
* @throws DateTimeException if unable to create the date
*/
@Override
public JapaneseDate dateYearDay(int prolepticYear, int dayOfYear) {
return new JapaneseDate(LocalDate.ofYearDay(prolepticYear, dayOfYear));
}
示例10: dateYearDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains a local date in Minguo calendar system from the
* proleptic-year and day-of-year fields.
*
* @param prolepticYear the proleptic-year
* @param dayOfYear the day-of-year
* @return the Minguo local date, not null
* @throws DateTimeException if unable to create the date
*/
@Override
public MinguoDate dateYearDay(int prolepticYear, int dayOfYear) {
return new MinguoDate(LocalDate.ofYearDay(prolepticYear + YEARS_DIFFERENCE, dayOfYear));
}
示例11: dateYearDay
import java.time.LocalDate; //导入方法依赖的package包/类
/**
* Obtains a local date in Thai Buddhist calendar system from the
* proleptic-year and day-of-year fields.
*
* @param prolepticYear the proleptic-year
* @param dayOfYear the day-of-year
* @return the Thai Buddhist local date, not null
* @throws DateTimeException if unable to create the date
*/
@Override
public ThaiBuddhistDate dateYearDay(int prolepticYear, int dayOfYear) {
return new ThaiBuddhistDate(LocalDate.ofYearDay(prolepticYear - YEARS_DIFFERENCE, dayOfYear));
}