Java Code Examples for java.time.LocalDateTime#getMonthValue()

The following examples show how to use java.time.LocalDateTime#getMonthValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimesheetServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public String computeFullName(Timesheet timesheet) {

  User timesheetUser = timesheet.getUser();
  LocalDateTime createdOn = timesheet.getCreatedOn();

  if (timesheetUser != null && createdOn != null) {
    return timesheetUser.getFullName()
        + " "
        + createdOn.getDayOfMonth()
        + "/"
        + createdOn.getMonthValue()
        + "/"
        + timesheet.getCreatedOn().getYear()
        + " "
        + createdOn.getHour()
        + ":"
        + createdOn.getMinute();
  } else if (timesheetUser != null) {
    return timesheetUser.getFullName() + " N°" + timesheet.getId();
  } else {
    return "N°" + timesheet.getId();
  }
}
 
Example 2
Source File: ZipUtils.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
private static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
Example 3
Source File: ZipUtils.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Converts Java time to DOS time.
 */
private static long javaToDosTime(long time) {
    Instant instant = Instant.ofEpochMilli(time);
    LocalDateTime ldt = LocalDateTime.ofInstant(
            instant, ZoneId.systemDefault());
    int year = ldt.getYear() - 1980;
    if (year < 0) {
        return (1 << 21) | (1 << 16);
    }
    return (year << 25 |
        ldt.getMonthValue() << 21 |
        ldt.getDayOfMonth() << 16 |
        ldt.getHour() << 11 |
        ldt.getMinute() << 5 |
        ldt.getSecond() >> 1) & 0xffffffffL;
}
 
Example 4
Source File: LeaveServiceImpl.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
public boolean willHaveEnoughDays(LeaveRequest leaveRequest) {

    LocalDateTime todayDate = appBaseService.getTodayDateTime().toLocalDateTime();
    LocalDateTime beginDate = leaveRequest.getFromDateT();

    int interval =
        (beginDate.getYear() - todayDate.getYear()) * 12
            + beginDate.getMonthValue()
            - todayDate.getMonthValue();
    BigDecimal num =
        leaveRequest
            .getLeaveLine()
            .getQuantity()
            .add(
                leaveRequest
                    .getUser()
                    .getEmployee()
                    .getWeeklyPlanning()
                    .getLeaveCoef()
                    .multiply(
                        leaveRequest.getLeaveLine().getLeaveReason().getDefaultDayNumberGain())
                    .multiply(BigDecimal.valueOf(interval)));

    return leaveRequest.getDuration().compareTo(num) <= 0;
  }
 
Example 5
Source File: DateMilliAccessor.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private Date getDate(int index, TimeZone tz) {
  if (ac.isNull(index)) {
    return null;
  }

  // The Arrow datetime values are already in UTC, so adjust to the timezone of the calendar passed in to
  // ensure the reported value is correct according to the JDBC spec.
  final LocalDateTime date = LocalDateTime.ofInstant(Instant.ofEpochMilli(ac.get(index)), tz.toZoneId());
  return new Date(date.getYear() - 1900, date.getMonthValue() - 1, date.getDayOfMonth());
}
 
Example 6
Source File: DataTypeCodec.java    From vertx-sql-client with Apache License 2.0 5 votes vote down vote up
private static void binaryEncodeDatetime(LocalDateTime value, ByteBuf buffer) {
  int year = value.getYear();
  int month = value.getMonthValue();
  int day = value.getDayOfMonth();
  int hour = value.getHour();
  int minute = value.getMinute();
  int second = value.getSecond();
  int microsecond = value.getNano() / 1000;

  // LocalDateTime does not have a zero value of month or day
  if (hour == 0 && minute == 0 && second == 0 && microsecond == 0) {
    buffer.writeByte(4);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
  } else if (microsecond == 0) {
    buffer.writeByte(7);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
    buffer.writeByte(hour);
    buffer.writeByte(minute);
    buffer.writeByte(second);
  } else {
    buffer.writeByte(11);
    buffer.writeShortLE(year);
    buffer.writeByte(month);
    buffer.writeByte(day);
    buffer.writeByte(hour);
    buffer.writeByte(minute);
    buffer.writeByte(second);
    buffer.writeIntLE(microsecond);
  }
}
 
Example 7
Source File: DateType.java    From tikv-client-lib-java with Apache License 2.0 5 votes vote down vote up
@Override
public Object decodeNotNull(int flag, CodecDataInput cdi) {
  long val = IntegerType.decodeNotNullPrimitive(flag, cdi);
  LocalDateTime localDateTime = fromPackedLong(val);
  if (localDateTime == null) {
    return null;
  }
  //TODO revisit this later.
  return new Date(localDateTime.getYear() - 1900,
      localDateTime.getMonthValue() - 1,
      localDateTime.getDayOfMonth());
}
 
Example 8
Source File: DataLabel.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DataLabel(LocalDateTime time) {
    _time = time;
    _year = time.getYear();
    _month = (short) time.getMonthValue();
    _day = (short) time.getDayOfMonth();
    _hour = (short) time.getHour();
}
 
Example 9
Source File: TimeFunctions.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String apply(LocalDateTime value) {
    int month = value.getMonthValue();
    String season;
    switch (month) {
        case 1:
        case 2:
        case 12:
            season = "Winter";
            break;
        case 3:
        case 4:
        case 5:
            season = "Spring";
            break;
        case 6:
        case 7:
        case 8:
            season = "Summer";
            break;
        case 9:
        case 10:
        case 11:
            season = "Autumn";
            break;
        default:
            season = "Null";
            break;
    }
    return season;
}
 
Example 10
Source File: DateTime.java    From Algorithms-and-Data-Structures-in-Java with GNU General Public License v3.0 4 votes vote down vote up
private static String addTwoDays() {
    LocalDateTime now = LocalDateTime.ofInstant(Instant.now(), ZoneId.of("UTC"));
    LocalDateTime afterTwoDays = now.plusDays(2);
    return afterTwoDays.getDayOfMonth() + "-" + afterTwoDays.getMonthValue() + "-" + afterTwoDays.getYear();
}
 
Example 11
Source File: FuzzyValues.java    From icure-backend with GNU General Public License v2.0 4 votes vote down vote up
public static long getFuzzyDate(LocalDateTime dateTime, TemporalUnit precision) {
	return dateTime.getYear() * 10000l + (precision == ChronoUnit.YEARS ? 0 : (
			dateTime.getMonthValue() * 100l + (precision == ChronoUnit.MONTHS ? 0 : (
					dateTime.getDayOfMonth()
			))));
}
 
Example 12
Source File: DefaultDateFunctions.java    From jackcess with Apache License 2.0 4 votes vote down vote up
private static int getQuarter(LocalDateTime ldt) {
  int month = ldt.getMonthValue() - 1;
  return (month / 3) + 1;
}
 
Example 13
Source File: Main.java    From Java-Coding-Problems with MIT License 4 votes vote down vote up
public static void main(String[] args) {

        System.out.println("Before JDK 8:");

        Date date = new Date();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        int yearC = calendar.get(Calendar.YEAR);
        int monthC = calendar.get(Calendar.MONTH);
        int weekC = calendar.get(Calendar.WEEK_OF_MONTH);
        int dayC = calendar.get(Calendar.DATE);
        int hourC = calendar.get(Calendar.HOUR_OF_DAY);
        int minuteC = calendar.get(Calendar.MINUTE);
        int secondC = calendar.get(Calendar.SECOND);
        int millisC = calendar.get(Calendar.MILLISECOND);

        System.out.println("Date: " + date);
        System.out.println("Year: " + yearC + " Month: " + monthC
                + " Week: " + weekC + " Day: " + dayC + " Hour: " + hourC
                + " Minute: " + minuteC + " Second: " + secondC + " Millis: " + millisC);

        System.out.println("\nStarting with JDK 8:");
        
        LocalDateTime ldt = LocalDateTime.now();
        
        int yearLDT = ldt.getYear();
        int monthLDT = ldt.getMonthValue();
        int dayLDT = ldt.getDayOfMonth();
        int hourLDT = ldt.getHour();
        int minuteLDT = ldt.getMinute();
        int secondLDT = ldt.getSecond();
        int nanoLDT = ldt.getNano();                

        System.out.println("LocalDateTime: " + ldt);
        System.out.println("Year: " + yearLDT + " Month: " + monthLDT
                + " Day: " + dayLDT + " Hour: " + hourLDT + " Minute: " + minuteLDT 
                + " Second: " + secondLDT + " Nano: " + nanoLDT);
        
        int yearLDT2 = ldt.get(ChronoField.YEAR);
        int monthLDT2 = ldt.get(ChronoField.MONTH_OF_YEAR);
        int dayLDT2 = ldt.get(ChronoField.DAY_OF_MONTH);
        int hourLDT2 = ldt.get(ChronoField.HOUR_OF_DAY);
        int minuteLDT2 = ldt.get(ChronoField.MINUTE_OF_HOUR);
        int secondLDT2 = ldt.get(ChronoField.SECOND_OF_MINUTE);
        int nanoLDT2 = ldt.get(ChronoField.NANO_OF_SECOND);                
        
        System.out.println("Year: " + yearLDT2 + " Month: " + monthLDT2
                + " Day: " + dayLDT2 + " Hour: " + hourLDT2 + " Minute: " + minuteLDT2
                + " Second: " + secondLDT2 + " Nano: " + nanoLDT2);
    }
 
Example 14
Source File: Timestamp.java    From jdk8u-dev-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 15
Source File: Timestamp.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 16
Source File: Timestamp.java    From JDKSourceCode1.8 with MIT License 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 17
Source File: Timestamp.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 18
Source File: Timestamp.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 19
Source File: Timestamp.java    From openjdk-8-source with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}
 
Example 20
Source File: Timestamp.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Obtains an instance of {@code Timestamp} from a {@code LocalDateTime}
 * object, with the same year, month, day of month, hours, minutes,
 * seconds and nanos date-time value as the provided {@code LocalDateTime}.
 * <p>
 * The provided {@code LocalDateTime} is interpreted as the local
 * date-time in the local time zone.
 *
 * @param dateTime a {@code LocalDateTime} to convert
 * @return a {@code Timestamp} object
 * @exception NullPointerException if {@code dateTime} is null.
 * @since 1.8
 */
@SuppressWarnings("deprecation")
public static Timestamp valueOf(LocalDateTime dateTime) {
    return new Timestamp(dateTime.getYear() - 1900,
                         dateTime.getMonthValue() - 1,
                         dateTime.getDayOfMonth(),
                         dateTime.getHour(),
                         dateTime.getMinute(),
                         dateTime.getSecond(),
                         dateTime.getNano());
}