org.joda.time.LocalDate.fromCalendarFields()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(4.8k)|赞(0)|评价(0)|浏览(127)

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

LocalDate.fromCalendarFields介绍

[英]Constructs a LocalDate from a java.util.Calendar using exactly the same field values.

Each field is queried from the Calendar and assigned to the LocalDate. This is useful if you have been using the Calendar as a local date, ignoring the zone.

One advantage of this method is that this method is unaffected if the version of the time zone data differs between the JDK and Joda-Time. That is because the local field values are transferred, calculated using the JDK time zone data and without using the Joda-Time time zone data.

This factory method ignores the type of the calendar and always creates a LocalDate with ISO chronology. It is expected that you will only pass in instances of GregorianCalendar however this is not validated.
[中]使用完全相同的字段值从java.util.Calendar构造LocalDate。
从日历中查询每个字段并将其分配给LocalDate。如果您一直将日历用作本地日期,而忽略区域,则此选项非常有用。
此方法的一个优点是,如果时区数据的版本在JDK和Joda时间之间不同,则此方法不受影响。这是因为本地字段值是使用JDK时区数据传输、计算的,而不使用Joda时区数据。
此factory方法忽略日历的类型,并始终使用ISO时间顺序创建LocalDate。预计您将只在GregorianCalendar的实例中传递,但这不会得到验证。

代码示例

代码示例来源:origin: joda-time/joda-time

return fromCalendarFields(cal);

代码示例来源:origin: JodaOrg/joda-time

return fromCalendarFields(cal);

代码示例来源:origin: JodaOrg/joda-time-hibernate

public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException {
  Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, string);
  if (timestamp == null) {
    return null;
  }
  if (timestamp instanceof Date) {
    return LocalDate.fromDateFields((Date) timestamp);
  } else if (timestamp instanceof Calendar) {
    return LocalDate.fromCalendarFields((Calendar) timestamp);
  }
  return new LocalDate(timestamp);
}

代码示例来源:origin: joda-time/joda-time-hibernate

public Object nullSafeGet(ResultSet resultSet, String string) throws SQLException {
  Object timestamp = StandardBasicTypes.DATE.nullSafeGet(resultSet, string);
  if (timestamp == null) {
    return null;
  }
  if (timestamp instanceof Date) {
    return LocalDate.fromDateFields((Date) timestamp);
  } else if (timestamp instanceof Calendar) {
    return LocalDate.fromCalendarFields((Calendar) timestamp);
  }
  return new LocalDate(timestamp);
}

代码示例来源:origin: io.virtdata/virtdata-lib-realer

return fromCalendarFields(cal);

代码示例来源:origin: Nextdoor/bender

return fromCalendarFields(cal);

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.joda-time

return fromCalendarFields(cal);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-analytics

return fromCalendarFields(cal);

代码示例来源:origin: com.ning.billing/killbill-osgi-bundles-jruby

return fromCalendarFields(cal);

代码示例来源:origin: org.kill-bill.billing/killbill-osgi-bundles-jruby

return fromCalendarFields(cal);

代码示例来源:origin: aaronshan/presto-third-functions

@ScalarFunction("dayOfWeek")
  @Description("Returns the day of week from a date string")
  @SqlType(StandardTypes.INTEGER)
  public static long dayOfWeek(@SqlType(StandardTypes.DATE) long date) {
    try {
      Calendar calendar = Calendar.getInstance();
      calendar.setTimeInMillis(DAYS.toMillis(date));
      LocalDate localDate = LocalDate.fromCalendarFields(calendar);
      return localDate.getDayOfWeek();
    } catch (Exception e) {
      return -1;
    }
  }
}

代码示例来源:origin: aaronshan/presto-third-functions

@ScalarFunction("typeOfDay")
  @Description("Returns the day of week from a date string")
  @SqlType(StandardTypes.INTEGER)
  public static long typeOfDay(@SqlType(StandardTypes.DATE) long date) {
    try {
      Calendar calendar = Calendar.getInstance();
      calendar.setTimeInMillis(DAYS.toMillis(date));
      LocalDate localDate = LocalDate.fromCalendarFields(calendar);

      String dateStr = localDate.toString(DEFAULT_DATE_FORMATTER);
      return typeOfDay(Slices.utf8Slice(dateStr));
    } catch (Exception e) {
    }

    return -1;
  }
}

代码示例来源:origin: aaronshan/presto-third-functions

@ScalarFunction("zodiac_cn")
@Description("from the input date string or separate month and day arguments, returns the chinese string of the Zodiac.")
@SqlType(StandardTypes.VARCHAR)
public static Slice getZodiacSignCn(@SqlType(StandardTypes.DATE) long t) {
  try {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(DAYS.toMillis(t));
    LocalDate date = LocalDate.fromCalendarFields(calendar);
    String zodiac = getZodiac(date.getMonthOfYear(), date.getDayOfMonth(), Language.CN);
    return Slices.utf8Slice(zodiac);
  } catch (Exception e) {
    return null;
  }
}

代码示例来源:origin: aaronshan/presto-third-functions

@ScalarFunction("zodiac")
@Description("from the input date string or separate month and day arguments, returns the string of the Zodiac.")
@SqlType(StandardTypes.VARCHAR)
public static Slice getZodiacSignEn(@SqlType(StandardTypes.DATE) long t) {
  try {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(DAYS.toMillis(t));
    LocalDate date = LocalDate.fromCalendarFields(calendar);
    String zodiac = getZodiac(date.getMonthOfYear(), date.getDayOfMonth(), Language.EN);
    return Slices.utf8Slice(zodiac);
  } catch (Exception e) {
    return null;
  }
}

相关文章