本文整理了Java中org.joda.time.LocalDateTime.getMonthOfYear()
方法的一些代码示例,展示了LocalDateTime.getMonthOfYear()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LocalDateTime.getMonthOfYear()
方法的具体详情如下:
包路径:org.joda.time.LocalDateTime
类名称:LocalDateTime
方法名:getMonthOfYear
[英]Get the month of year field value.
[中]获取“月份”字段值。
代码示例来源:origin: qunarcorp/qmq
private static long month(final LocalDateTime localDateTime) {
return localDateTime.getMonthOfYear() * 1000000L;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
protected Calendar dateToCalendar(Date date, TimeZone offerTimeZone) {
DateTimeZone offerDateTimeZone = DateTimeZone.forTimeZone(offerTimeZone);
LocalDateTime offerDateTime = new LocalDateTime(date, offerDateTimeZone);
Calendar calendar = new GregorianCalendar(offerTimeZone);
calendar.set(Calendar.YEAR, offerDateTime.getYear());
calendar.set(Calendar.MONTH, offerDateTime.getMonthOfYear() - 1);
calendar.set(Calendar.DAY_OF_MONTH, offerDateTime.getDayOfMonth());
calendar.set(Calendar.HOUR_OF_DAY, offerDateTime.getHourOfDay());
calendar.set(Calendar.MINUTE, offerDateTime.getMinuteOfHour());
calendar.set(Calendar.SECOND, offerDateTime.getSecondOfMinute());
calendar.get(Calendar.HOUR_OF_DAY);//do not delete this line
calendar.get(Calendar.MINUTE);
return calendar;
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Get the date time as a <code>java.util.Date</code> using the specified time zone.
* <p>
* The <code>Date</code> object created has exactly the same fields as this
* date-time, except when the time would be invalid due to a daylight savings
* gap. In that case, the time will be set to the earliest valid time after the gap.
* <p>
* In the case of a daylight savings overlap, the earlier instant is selected.
* <p>
* Converting to a JDK Date is full of complications as the JDK Date constructor
* doesn't behave as you might expect around DST transitions. This method works
* by taking a first guess and then adjusting. This also handles the situation
* where the JDK time zone data differs from the Joda-Time time zone data.
* <p>
* Unlike {@link #toDate()}, this implementation does not rely on Java's synchronized
* time zone initialization logic, and should demonstrate better concurrent performance
* characteristics.
*
* @return a Date initialised with this date-time, never null
* @since 2.3
*/
public Date toDate(final TimeZone timeZone) {
final Calendar calendar = Calendar.getInstance(timeZone);
calendar.clear();
calendar.set(getYear(), getMonthOfYear() - 1, getDayOfMonth(),
getHourOfDay(), getMinuteOfHour(), getSecondOfMinute());
Date date = calendar.getTime();
date.setTime(date.getTime() + getMillisOfSecond());
return correctDstTransition(date, timeZone);
}
代码示例来源:origin: joda-time/joda-time
/**
* Get the date time as a <code>java.util.Date</code> using the specified time zone.
* <p>
* The <code>Date</code> object created has exactly the same fields as this
* date-time, except when the time would be invalid due to a daylight savings
* gap. In that case, the time will be set to the earliest valid time after the gap.
* <p>
* In the case of a daylight savings overlap, the earlier instant is selected.
* <p>
* Converting to a JDK Date is full of complications as the JDK Date constructor
* doesn't behave as you might expect around DST transitions. This method works
* by taking a first guess and then adjusting. This also handles the situation
* where the JDK time zone data differs from the Joda-Time time zone data.
* <p>
* Unlike {@link #toDate()}, this implementation does not rely on Java's synchronized
* time zone initialization logic, and should demonstrate better concurrent performance
* characteristics.
*
* @return a Date initialised with this date-time, never null
* @since 2.3
*/
public Date toDate(final TimeZone timeZone) {
final Calendar calendar = Calendar.getInstance(timeZone);
calendar.clear();
calendar.set(getYear(), getMonthOfYear() - 1, getDayOfMonth(),
getHourOfDay(), getMinuteOfHour(), getSecondOfMinute());
Date date = calendar.getTime();
date.setTime(date.getTime() + getMillisOfSecond());
return correctDstTransition(date, timeZone);
}
代码示例来源:origin: joda-time/joda-time
/**
* Get the date time as a <code>java.util.Date</code>.
* <p>
* The <code>Date</code> object created has exactly the same fields as this
* date-time, except when the time would be invalid due to a daylight savings
* gap. In that case, the time will be set to the earliest valid time after the gap.
* <p>
* In the case of a daylight savings overlap, the earlier instant is selected.
* <p>
* Converting to a JDK Date is full of complications as the JDK Date constructor
* doesn't behave as you might expect around DST transitions. This method works
* by taking a first guess and then adjusting. This also handles the situation
* where the JDK time zone data differs from the Joda-Time time zone data.
*
* @return a Date initialised with this date-time, never null
* @since 2.0
*/
@SuppressWarnings("deprecation")
public Date toDate() {
int dom = getDayOfMonth();
Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom,
getHourOfDay(), getMinuteOfHour(), getSecondOfMinute());
date.setTime(date.getTime() + getMillisOfSecond());
return correctDstTransition(date, TimeZone.getDefault());
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Get the date time as a <code>java.util.Date</code>.
* <p>
* The <code>Date</code> object created has exactly the same fields as this
* date-time, except when the time would be invalid due to a daylight savings
* gap. In that case, the time will be set to the earliest valid time after the gap.
* <p>
* In the case of a daylight savings overlap, the earlier instant is selected.
* <p>
* Converting to a JDK Date is full of complications as the JDK Date constructor
* doesn't behave as you might expect around DST transitions. This method works
* by taking a first guess and then adjusting. This also handles the situation
* where the JDK time zone data differs from the Joda-Time time zone data.
*
* @return a Date initialised with this date-time, never null
* @since 2.0
*/
@SuppressWarnings("deprecation")
public Date toDate() {
int dom = getDayOfMonth();
Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom,
getHourOfDay(), getMinuteOfHour(), getSecondOfMinute());
date.setTime(date.getTime() + getMillisOfSecond());
return correctDstTransition(date, TimeZone.getDefault());
}
代码示例来源:origin: apache/incubator-pinot
private Object getRandomValueForTimeColumn(boolean isSimpleDate) {
long randomMs = ThreadLocalRandom.current().nextLong(startTime);
long dateColVal = randomMs;
Object result;
if (isSimpleDate) {
DateTime dateTime = new DateTime(randomMs);
LocalDateTime localDateTime = dateTime.toLocalDateTime();
int year = localDateTime.getYear();
int month = localDateTime.getMonthOfYear();
int day = localDateTime.getDayOfMonth();
String dateColStr = String.format("%04d%02d%02d", year, month, day);
dateColVal = Integer.valueOf(dateColStr);
result = new Integer(Integer.valueOf(dateColStr));
} else {
result = new Long(dateColVal);
}
if (dateColVal < minTime) {
minTime = dateColVal;
}
if (dateColVal > maxTime) {
maxTime = dateColVal;
}
return result;
}
代码示例来源:origin: joda-time/joda-time
/**
* Converts this object to a DateTime using the specified zone.
* <p>
* When the time zone is applied, the local date-time may be affected by daylight saving.
* In a daylight saving gap, when the local time does not exist,
* this method will throw an exception.
* In a daylight saving overlap, when the same local time occurs twice,
* this method returns the first occurrence of the local time.
*
* @param zone time zone to apply, or default if null
* @return a DateTime using the same millis
* @throws IllegalInstantException if the local time does not exist when the time zone is applied
*/
public DateTime toDateTime(DateTimeZone zone) {
zone = DateTimeUtils.getZone(zone);
Chronology chrono = iChronology.withZone(zone);
return new DateTime(
getYear(), getMonthOfYear(), getDayOfMonth(),
getHourOfDay(), getMinuteOfHour(),
getSecondOfMinute(), getMillisOfSecond(), chrono);
}
代码示例来源:origin: JodaOrg/joda-time
/**
* Converts this object to a DateTime using the specified zone.
* <p>
* When the time zone is applied, the local date-time may be affected by daylight saving.
* In a daylight saving gap, when the local time does not exist,
* this method will throw an exception.
* In a daylight saving overlap, when the same local time occurs twice,
* this method returns the first occurrence of the local time.
*
* @param zone time zone to apply, or default if null
* @return a DateTime using the same millis
* @throws IllegalInstantException if the local time does not exist when the time zone is applied
*/
public DateTime toDateTime(DateTimeZone zone) {
zone = DateTimeUtils.getZone(zone);
Chronology chrono = iChronology.withZone(zone);
return new DateTime(
getYear(), getMonthOfYear(), getDayOfMonth(),
getHourOfDay(), getMinuteOfHour(),
getSecondOfMinute(), getMillisOfSecond(), chrono);
}
代码示例来源:origin: camunda/camunda-bpm-platform
public Date toDate() {
int dom = getDayOfMonth();
Date date = new Date(getYear() - 1900, getMonthOfYear() - 1, dom,
getHourOfDay(), getMinuteOfHour(), getSecondOfMinute());
date.setTime(date.getTime() + getMillisOfSecond());
代码示例来源:origin: camunda/camunda-bpm-platform
/**
* Converts this object to a DateTime using the specified zone.
* <p>
* This method will throw an exception if the datetime that would be
* created does not exist when the time zone is taken into account.
*
* @param zone time zone to apply, or default if null
* @return a DateTime using the same millis
*/
public DateTime toDateTime(DateTimeZone zone) {
zone = DateTimeUtils.getZone(zone);
Chronology chrono = iChronology.withZone(zone);
return new DateTime(
getYear(), getMonthOfYear(), getDayOfMonth(),
getHourOfDay(), getMinuteOfHour(),
getSecondOfMinute(), getMillisOfSecond(), chrono);
}
代码示例来源:origin: org.assertj/assertj-joda-time
/**
* Returns true if both datetime are in the same year and month, false otherwise.
*
* @param actual the actual datetime. expected not be null
* @param other the other datetime. expected not be null
* @return true if both datetime are in the same year and month, false otherwise
*/
private static boolean haveSameYearAndMonth(LocalDateTime actual, LocalDateTime other) {
return haveSameYear(actual, other) && actual.getMonthOfYear() == other.getMonthOfYear();
}
代码示例来源:origin: dremio/dremio-oss
@Override
public Date getDate(int index) {
if (ac.isNull(index)) {
return null;
}
org.joda.time.LocalDateTime date = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
return new Date(date.getYear() - 1900, date.getMonthOfYear() - 1, date.getDayOfMonth());
}
代码示例来源:origin: arnaudroger/SimpleFlatMapper
@Override
public java.time.LocalDateTime convert(LocalDateTime in, Context context) throws Exception {
if (in == null) return null;
return java.time.LocalDateTime.of(in.getYear(), in.getMonthOfYear(), in.getDayOfMonth(), in.getHourOfDay(), in.getMinuteOfHour(), in.getSecondOfMinute(), in.getMillisOfSecond() * 1000);
}
}
代码示例来源:origin: dremio/dremio-oss
@Override
public Timestamp getTimestamp(int index) {
if (ac.isNull(index)) {
return null;
}
org.joda.time.LocalDateTime date = new org.joda.time.LocalDateTime(ac.get(index), org.joda.time.DateTimeZone.UTC);
return new Timestamp(date.getYear() - 1900,
date.getMonthOfYear() - 1,
date.getDayOfMonth(),
date.getHourOfDay(),
date.getMinuteOfHour(),
date.getSecondOfMinute(),
(int) java.util.concurrent.TimeUnit.MILLISECONDS.toNanos(date.getMillisOfSecond()));
}
代码示例来源:origin: dremio/dremio-oss
@Override
public void setup() {
int timeZoneIndex = contextInfo.getRootFragmentTimeZone();
org.joda.time.DateTimeZone timeZone = org.joda.time.DateTimeZone.forID(org.apache.arrow.vector.util.DateUtility.getTimeZone(timeZoneIndex));
org.joda.time.LocalDateTime now = new org.joda.time.LocalDateTime(contextInfo.getQueryStartTime(), timeZone);
queryStartDate = (new org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), timeZone)).
withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
}
代码示例来源:origin: dremio/dremio-oss
@Override
public void setup() {
org.joda.time.LocalDateTime now = new org.joda.time.LocalDateTime(contextInfo.getQueryStartTime(), org.joda.time.DateTimeZone.UTC);
queryStartDate = (new org.joda.time.DateMidnight(now.getYear(), now.getMonthOfYear(), now.getDayOfMonth(), org.joda.time.DateTimeZone.UTC)).
withZoneRetainFields(org.joda.time.DateTimeZone.UTC).getMillis();
}
代码示例来源:origin: de.javakaffee/kryo-serializers
@Override
public void write(Kryo kryo, Output output, LocalDateTime localDateTime) {
final int packedYearMonthDay = localDateTime.getYear() * 13 * 32 +
localDateTime.getMonthOfYear() * 32 +
localDateTime.getDayOfMonth();
output.writeLong((long)packedYearMonthDay * 86400000 + localDateTime.getMillisOfDay(), true);
final String chronologyId =
IdentifiableChronology.getChronologyId(localDateTime.getChronology());
output.writeString(chronologyId == null ? "" : chronologyId);
}
}
代码示例来源:origin: magro/kryo-serializers
@Override
public void write(Kryo kryo, Output output, LocalDateTime localDateTime) {
final int packedYearMonthDay = localDateTime.getYear() * 13 * 32 +
localDateTime.getMonthOfYear() * 32 +
localDateTime.getDayOfMonth();
output.writeLong((long)packedYearMonthDay * 86400000 + localDateTime.getMillisOfDay(), true);
final String chronologyId =
IdentifiableChronology.getChronologyId(localDateTime.getChronology());
output.writeString(chronologyId == null ? "" : chronologyId);
}
}
代码示例来源:origin: dremio/dremio-oss
@Override
public RexNode convertCall(SqlRexContext cx, SqlCall call) {
final int timeZoneIndex = getContextInformation().getRootFragmentTimeZone();
final DateTimeZone timeZone = DateTimeZone.forID(DateUtility.getTimeZone(timeZoneIndex));
final LocalDateTime dateTime = new LocalDateTime(getContextInformation().getQueryStartTime(), timeZone);
final long midNightAsMillis =
new DateMidnight(dateTime.getYear(), dateTime.getMonthOfYear(), dateTime.getDayOfMonth(),
timeZone)
.withZoneRetainFields(DateTimeZone.UTC)
.getMillis();
return cx.getRexBuilder()
.makeDateLiteral(DateTimes.toDateTime(
new LocalDateTime(midNightAsMillis, DateTimeZone.UTC))
.toCalendar(null)); // null sets locale to default locale
}
}
内容来源于网络,如有侵权,请联系作者删除!