當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDateTime.getMonthValue方法代碼示例

本文整理匯總了Java中java.time.LocalDateTime.getMonthValue方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDateTime.getMonthValue方法的具體用法?Java LocalDateTime.getMonthValue怎麽用?Java LocalDateTime.getMonthValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDateTime的用法示例。


在下文中一共展示了LocalDateTime.getMonthValue方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static void main(String[] args) {
    LocalDateTime prizeCeremony = LocalDateTime.parse("2050-06-05T14:00:00");
    LocalDateTime dateTimeNow = LocalDateTime.now();

    if (prizeCeremony.getMonthValue() == 6)
        System.out.println("Can't invite president");
    else
        System.out.println("President invited");

    LocalDateTime chiefGuestDeparture = LocalDateTime.parse("2050-06-05T14:30:00");

    if (prizeCeremony.plusHours(2).isAfter(chiefGuestDeparture))
        System.out.println("Chief Guest will leave before ceremony completes");

    LocalDateTime eventMgrArrival = LocalDateTime.of(2050, 6, 5, 14, 14, 30, 0);
    if (eventMgrArrival.isAfter(prizeCeremony.minusHours(3)))
        System.out.println("Manager is supposed to arrive 3 hrs earlier");
}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:19,代碼來源:Main.java

示例2: writeDateTimeUntil

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static void writeDateTimeUntil(LocalDateTime dateTime, ByteArrayOutputStream bos) {
    // this is frigging confusing.. who the hell did think about this...
    // the first three bits are the months
    // next five bits are the day
    // next bit is always 0
    // next bit is the month again (the very first one)
    // next bit is always 0
    // last five bits are the year

    // only the first three bits!

    // int month = (positiveFirst >> 5 << 1) + (64 >> 6 & 1);
    int month = dateTime.getMonthValue();
    int monthAndDay = (month << 4 & 224) + dateTime.getDayOfMonth();
    bos.write(monthAndDay);

    int monthAndYear = (month % 2 == 1 ? 128 : 0) + (dateTime.getYear() - 2000);
    bos.write(monthAndYear);

    int halfhours = (dateTime.getHour() * 2) + (dateTime.getMinute() == 30 ? 1 : 0);
    bos.write(halfhours);
}
 
開發者ID:spinscale,項目名稱:maxcube-java,代碼行數:23,代碼來源:Generator.java

示例3: javaToDosTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:ZipUtils.java

示例4: dateFormatterForLogs

import java.time.LocalDateTime; //導入方法依賴的package包/類
private static String dateFormatterForLogs(LocalDateTime dateTime) {
    String dateString = "[";
    dateString += dateTime.getDayOfMonth() + "_";
    dateString += dateTime.getMonthValue() + "_";
    dateString += dateTime.getYear() + "_";
    dateString += dateTime.getHour() + ":";
    dateString += dateTime.getMinute() + ":";
    dateString += dateTime.getSecond();
    dateString += "] ";
    return dateString;
}
 
開發者ID:samurayrj,項目名稱:rubenlagus-TelegramBots,代碼行數:12,代碼來源:FileFormatter.java

示例5: splitDatesIntoMonths

import java.time.LocalDateTime; //導入方法依賴的package包/類
public static List<Date[]> splitDatesIntoMonths(Date from, Date to) throws IllegalArgumentException {

    List<Date[]> dates = new ArrayList<>();

    LocalDateTime dFrom = asLocalDateTime(from);
    LocalDateTime dTo = asLocalDateTime(to);

    if (dFrom.compareTo(dTo) >= 0) {
      throw new IllegalArgumentException("Provide a to-date greater than the from-date");
    }

    while (dFrom.compareTo(dTo) < 0) {
      // check if current time frame is last
      boolean isLastTimeFrame = dFrom.getMonthValue() == dTo.getMonthValue() && dFrom.getYear() == dTo.getYear();

      // define day of month based on timeframe. if last - take boundaries from end date, else end of month and date
      int dayOfMonth = isLastTimeFrame ? dTo.getDayOfMonth() : dFrom.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
      LocalTime time = isLastTimeFrame ? dTo.toLocalTime() : LocalTime.MAX;


      // build timeframe
      Date[] dar = new Date[2];
      dar[0] = asDate(dFrom);
      dar[1] = asDate(dFrom.withDayOfMonth(dayOfMonth).toLocalDate().atTime(time));

      // add current timeframe
      dates.add(dar);

      // jump to beginning of next month
      dFrom = dFrom.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
    }

    return dates;

  }
 
開發者ID:YagelNasManit,項目名稱:environment.monitor,代碼行數:36,代碼來源:DataUtils.java

示例6: decodeNotNull

import java.time.LocalDateTime; //導入方法依賴的package包/類
@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());
}
 
開發者ID:pingcap,項目名稱:tikv-client-lib-java,代碼行數:13,代碼來源:DateType.java

示例7: javaToDosTime

import java.time.LocalDateTime; //導入方法依賴的package包/類
public 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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:ZipUtils.java

示例8: DateTimeParameterObject

import java.time.LocalDateTime; //導入方法依賴的package包/類
DateTimeParameterObject(final LocalDateTime localDateTime, @Nullable final String pattern) {
	this.localDateTime = localDateTime;
	this.pattern = Optional.ofNullable(pattern);
	this.dayOfMonth = localDateTime.getDayOfMonth();
	this.month = localDateTime.getMonthValue();
	this.year = localDateTime.getYear();
	this.hour = localDateTime.getHour();
	this.minute = localDateTime.getMinute();
	this.second = localDateTime.getSecond();
	this.instant = localDateTime.atZone(ZoneId.systemDefault()).toEpochSecond();
}
 
開發者ID:rooting-company,項目名稱:roxana,代碼行數:12,代碼來源:DateTimeParameterObject.java

示例9: testDateTimeInfo

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 獲取時間節點的詳細信息
 */
@Test
public void testDateTimeInfo(){
    LocalDateTime ldt = LocalDateTime.now();

    // 獲取當前的年份
    int year = ldt.getYear();
    System.out.println(year);

    // 當前年中的第幾天
    int dayOfYear = ldt.getDayOfYear();
    System.out.println(dayOfYear);

    // 當前月份中的第幾天
    int dayOfMonth = ldt.getDayOfMonth();
    System.out.println(dayOfMonth);

    // 當前周中的第幾天
    DayOfWeek dayOfWeek = ldt.getDayOfWeek();
    int dayOfWeekValue = dayOfWeek.getValue();
    System.out.println(dayOfWeekValue);

    // 獲取小時
    int hour = ldt.getHour();
    System.out.println(hour);

    // 獲取月份信息
    Month month = ldt.getMonth();
    int monthValue = month.getValue();
    System.out.println(monthValue);
    int ldtMonthValue = ldt.getMonthValue();
    System.out.println(ldtMonthValue);

    // 獲取分鍾
    int minute = ldt.getMinute();
    System.out.println(minute);
}
 
開發者ID:cbooy,項目名稱:cakes,代碼行數:40,代碼來源:LocalDateTimeDemo.java

示例10: valueOf

import java.time.LocalDateTime; //導入方法依賴的package包/類
/**
 * 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());
}
 
開發者ID:madHEYsia,項目名稱:ClassroomFlipkart,代碼行數:24,代碼來源:Timestamp.java


注:本文中的java.time.LocalDateTime.getMonthValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。