org.threeten.bp.LocalDate类的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.9k)|赞(0)|评价(0)|浏览(271)

本文整理了Java中org.threeten.bp.LocalDate类的一些代码示例,展示了LocalDate类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDate类的具体详情如下:
包路径:org.threeten.bp.LocalDate
类名称:LocalDate

LocalDate介绍

[英]A date without a time-zone in the ISO-8601 calendar system, such as 2007-12-23.

LocalDate is an immutable date-time object that represents a date, often viewed as year-month-day. Other date fields, such as day-of-year, day-of-week and week-of-year, can also be accessed. For example, the value "2nd October 2007" can be stored in a LocalDate.

This class does not store or represent a time or time-zone. Instead, it is a description of the date, as used for birthdays. It cannot represent an instant on the time-line without additional information such as an offset or time-zone.

The ISO-8601 calendar system is the modern civil calendar system used today in most of the world. It is equivalent to the proleptic Gregorian calendar system, in which today's rules for leap years are applied for all time. For most applications written today, the ISO-8601 rules are entirely suitable. However, any application that makes use of historical dates, and requires them to be accurate will find the ISO-8601 approach unsuitable.

Specification for implementors

This class is immutable and thread-safe.
[中]ISO-8601日历系统中没有时区的日期,如2007-12-23。
LocalDate是一个不可变的日期时间对象,它表示一个日期,通常被视为年-月-日。还可以访问其他日期字段,例如年中的日期、周中的日期和年中的周。例如,值“2007年10月2日”可以存储在LocalDate中。
此类不存储或表示时间或时区。相反,它是对日期的描述,用于生日。如果没有诸如偏移量或时区之类的附加信息,它不能表示时间线上的某个瞬间。
ISO-8601日历系统是当今世界大部分地区使用的现代民用日历系统。它相当于公历的前身,即今天的闰年规则在任何时候都适用。对于今天编写的大多数应用程序,ISO-8601规则完全适用。然而,任何使用历史日期并要求其准确的应用程序都会发现ISO-8601方法不合适。
####实施者规范
这个类是不可变的,并且是线程安全的。

代码示例

代码示例来源:origin: prolificinteractive/material-calendarview

@Override protected void onCreate(final Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_basic);
 ButterKnife.bind(this);
 // Add a decorator to disable prime numbered days
 widget.addDecorator(new PrimeDayDisableDecorator());
 // Add a second decorator that explicitly enables days <= 10. This will work because
 // decorators are applied in order, and the system allows re-enabling
 widget.addDecorator(new EnableOneToTenDecorator());
 final LocalDate calendar = LocalDate.now();
 widget.setSelectedDate(calendar);
 final LocalDate min = LocalDate.of(calendar.getYear(), Month.JANUARY, 1);
 final LocalDate max = LocalDate.of(calendar.getYear() + 1, Month.OCTOBER, 31);
 widget.state().edit()
   .setMinimumDate(min)
   .setMaximumDate(max)
   .commit();
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
public String toString() {
 return "CalendarDay{" + date.getYear() + "-" + date.getMonthValue() + "-"
   + date.getDayOfMonth() + "}";
}

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * Clear the previous selection, select the range of days from first to last, and finally
 * invalidate. First day should be before last day, otherwise the selection won't happen.
 *
 * @param first The first day of the range.
 * @param last The last day in the range.
 * @see CalendarPagerAdapter#setDateSelected(CalendarDay, boolean)
 */
public void selectRange(final CalendarDay first, final CalendarDay last) {
 selectedDates.clear();
 // Copy to start from the first day and increment
 LocalDate temp = LocalDate.of(first.getYear(), first.getMonth(), first.getDay());
 // for comparison
 final LocalDate end = last.getDate();
 while( temp.isBefore(end) || temp.equals(end) ) {
  selectedDates.add(CalendarDay.from(temp));
  temp = temp.plusDays(1);
 }
 invalidateSelectedDates();
}

代码示例来源:origin: prolificinteractive/material-calendarview

public StateBuilder() {
 calendarMode = CalendarMode.MONTHS;
 firstDayOfWeek =
   LocalDate.now().with(WeekFields.of(Locale.getDefault()).dayOfWeek(), 1).getDayOfWeek();
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override
protected List<CalendarDay> doInBackground(@NonNull Void... voids) {
 try {
  Thread.sleep(2000);
 } catch (InterruptedException e) {
  e.printStackTrace();
 }
 LocalDate temp = LocalDate.now().minusMonths(2);
 final ArrayList<CalendarDay> dates = new ArrayList<>();
 for (int i = 0; i < 30; i++) {
  final CalendarDay day = CalendarDay.from(temp);
  dates.add(day);
  temp = temp.plusDays(5);
 }
 return dates;
}

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains an instance of {@code LocalDate} from a text string such as {@code 2007-12-23}.
 * <p>
 * The string must represent a valid date and is parsed using
 * {@link org.threeten.bp.format.DateTimeFormatter#ISO_LOCAL_DATE}.
 *
 * @param text  the text to parse such as "2007-12-23", not null
 * @return the parsed local date, not null
 * @throws DateTimeParseException if the text cannot be parsed
 */
public static LocalDate parse(CharSequence text) {
  return parse(text, DateTimeFormatter.ISO_LOCAL_DATE);
}

代码示例来源:origin: com.github.joschi.jackson/jackson-datatype-threetenbp

@Override
public void serialize(LocalDate date, JsonGenerator generator, SerializerProvider provider) throws IOException
{
  if (useTimestamp(provider)) {
    generator.writeStartArray();
    generator.writeNumber(date.getYear());
    generator.writeNumber(date.getMonthValue());
    generator.writeNumber(date.getDayOfMonth());
    generator.writeEndArray();
  } else {
    String str = (_formatter == null) ? date.toString() : date.format(_formatter);
    generator.writeString(str);
  }
}

代码示例来源:origin: ThreeTen/threetenbp

@Override
public int lengthOfYear() {
  Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
  jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
  jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
  return  jcal.getActualMaximum(Calendar.DAY_OF_YEAR);
}

代码示例来源:origin: org.threeten/threetenbp

void adjustToFowards(int year) {
    if (adjustForwards == false && dayOfMonth > 0) {
      LocalDate adjustedDate = LocalDate.of(year, month, dayOfMonth).minusDays(6);
      dayOfMonth = adjustedDate.getDayOfMonth();
      month = adjustedDate.getMonth();
      adjustForwards = true;
    }
  }
}

代码示例来源:origin: com.torodb.torod.backends/postgresql

@Override
public Void visit(ScalarDate value, StringBuilder arg) {
  arg.append('\'')
      //this prints the value on ISO-8601, which is the recommended format on PostgreSQL
      .append(value.getValue().toString())
      .append('\'');
  return null;
}

代码示例来源:origin: ThreeTen/threetenbp

private static int getWeekRange(int wby) {
  LocalDate date = LocalDate.of(wby, 1, 1);
  // 53 weeks if standard year starts on Thursday, or Wed in a leap year
  if (date.getDayOfWeek() == THURSDAY || (date.getDayOfWeek() == WEDNESDAY && date.isLeapYear())) {
    return 53;
  }
  return 52;
}

代码示例来源:origin: ThreeTen/threetenbp

private static int getWeekBasedYear(LocalDate date) {
    int year = date.getYear();
    int doy = date.getDayOfYear();
    if (doy <= 3) {
      int dow = date.getDayOfWeek().ordinal();
      if (doy - dow < -2) {
        year--;
      }
    } else if (doy >= 363) {
      int dow = date.getDayOfWeek().ordinal();
      doy = doy - 363 - (date.isLeapYear() ? 1 : 0);
      if (doy - dow >= 0) {
        year++;
      }
    }
    return year;
  }
}

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * @param year new instance's year
 * @param month new instance's month as defined by {@linkplain java.util.Calendar}
 * @param day new instance's day of month
 */
private CalendarDay(final int year, final int month, final int day) {
 date = LocalDate.of(year, month, day);
}

代码示例来源:origin: shrikanth7698/Collapsible-Calendar-View-Android

LocalDate today = LocalDate.now();
collapsibleCalendar.addEventTag(today);
LocalDate tomorrow = today.plusDays(1);
collapsibleCalendar.addEventTag(tomorrow, Color.BLUE);
Log.d("Testing date ", collapsibleCalendar.getSelectedDay().toString());
collapsibleCalendar.setCalendarListener(new CollapsibleCalendar.CalendarListener() {
  @Override

代码示例来源:origin: ThreeTen/threetenbp

/**
 * Obtains the current month-day from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current month-day.
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current month-day, not null
 */
public static MonthDay now(Clock clock) {
  final LocalDate now = LocalDate.now(clock);  // called once
  return MonthDay.of(now.getMonth(), now.getDayOfMonth());
}

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * Get a new instance set to today
 *
 * @return CalendarDay set to today's date
 */
@NonNull public static CalendarDay today() {
 return from(LocalDate.now());
}

代码示例来源:origin: prolificinteractive/material-calendarview

@Override public boolean equals(Object o) {
 return o instanceof CalendarDay && date.equals(((CalendarDay) o).getDate());
}

代码示例来源:origin: prolificinteractive/material-calendarview

/**
 * Get the year
 *
 * @return the year for this day
 */
public int getYear() {
 return date.getYear();
}

代码示例来源:origin: org.threeten/threetenbp

/**
 * Obtains the current year from the specified clock.
 * <p>
 * This will query the specified clock to obtain the current year.
 * Using this method allows the use of an alternate clock for testing.
 * The alternate clock may be introduced using {@link Clock dependency injection}.
 *
 * @param clock  the clock to use, not null
 * @return the current year, not null
 */
public static Year now(Clock clock) {
  final LocalDate now = LocalDate.now(clock);  // called once
  return Year.of(now.getYear());
}

代码示例来源:origin: SouthernBox/NestedCalendar

@Override
  public void onDateSelected(@NonNull MaterialCalendarView widget,
                @NonNull CalendarDay calendarDay,
                boolean selected) {
    LocalDate localDate = calendarDay.getDate();
    WeekFields weekFields = WeekFields.of(Locale.getDefault());
    calendarBehavior.setWeekOfMonth(localDate.get(weekFields.weekOfMonth()));
    if (selected) {
      dayOfWeek = localDate.getDayOfWeek().getValue();
      dayOfMonth = localDate.getDayOfMonth();
    }
  }
});

相关文章