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

The following examples show how to use java.time.LocalDateTime#getMonth() . These examples are extracted from open source projects. 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 Project: schedge   File: Term.java    License: MIT License 6 votes vote down vote up
public static int getSemester(LocalDateTime time) {
  switch (time.getMonth()) {
  case JANUARY:
    return JANUARY;
  case FEBRUARY:
  case MARCH:
  case APRIL:
  case MAY:
    return SPRING;
  case JUNE:
  case JULY:
  case AUGUST:
    return SUMMER;
  case SEPTEMBER:
  case OCTOBER:
  case NOVEMBER:
  case DECEMBER:
    return FALL;
  default:
    throw new RuntimeException("Did they add another month? month=" +
                               time.getMonth());
  }
}
 
Example 2
Source Project: vertx-in-action   File: EventsVerticle.java    License: MIT License 6 votes vote down vote up
private Flowable<KafkaConsumerRecord<String, JsonObject>> generateActivityUpdate(KafkaConsumerRecord<String, JsonObject> record) {
  String deviceId = record.value().getString("deviceId");
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  return pgPool
    .preparedQuery(stepsCountForToday())
    .rxExecute(Tuple.of(deviceId))
    .map(rs -> rs.iterator().next())
    .map(row -> new JsonObject()
      .put("deviceId", deviceId)
      .put("timestamp", row.getTemporal(0).toString())
      .put("stepsCount", row.getLong(1)))
    .flatMap(json -> updateProducer.rxSend(KafkaProducerRecord.create("daily.step.updates", key, json)))
    .map(rs -> record)
    .toFlowable();
}
 
Example 3
@Test
@Tag("PASSING")
@Order(1)
public void verifyMonth() {

    LocalDateTime tOJDateTime = LocalDateTime.now(terminatorOriginalJudgementDay);

    // TODO: Replace the "null" below get a Month instance.
    //  Check: java.time.LocalDateTime.getMonth()
    Month tOJMonth = tOJDateTime.getMonth();

    assertEquals(Month.AUGUST,
            tOJMonth,
            "The Month enumeration should match August.");
}
 
Example 4
Source Project: vertx-in-action   File: CongratsTest.java    License: MIT License 5 votes vote down vote up
private KafkaProducerRecord<String, JsonObject> record(String deviceId, long steps) {
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  JsonObject json = new JsonObject()
    .put("deviceId", deviceId)
    .put("timestamp", now.toString())
    .put("stepsCount", steps);
  return KafkaProducerRecord.create("daily.step.updates", key, json);
}
 
Example 5
Source Project: vertx-in-action   File: EventStatsTest.java    License: MIT License 5 votes vote down vote up
private KafkaProducerRecord<String, JsonObject> dailyStepsUpdateRecord(String deviceId, long steps) {
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  JsonObject json = new JsonObject()
    .put("deviceId", deviceId)
    .put("timestamp", now.toString())
    .put("stepsCount", steps);
  return KafkaProducerRecord.create("daily.step.updates", key, json);
}
 
Example 6
Source Project: vertx-in-action   File: EventStatsTest.java    License: MIT License 5 votes vote down vote up
private KafkaProducerRecord<String, JsonObject> incomingStepsRecord(String deviceId, long syncId, long steps) {
  LocalDateTime now = LocalDateTime.now();
  String key = deviceId + ":" + now.getYear() + "-" + now.getMonth() + "-" + now.getDayOfMonth();
  JsonObject json = new JsonObject()
    .put("deviceId", deviceId)
    .put("syncId", syncId)
    .put("stepsCount", steps);
  return KafkaProducerRecord.create("incoming.steps", key, json);
}
 
Example 7
Source Project: javase   File: Java8TestLocalDateTime.java    License: MIT License 5 votes vote down vote up
public void testLocalDateTime(){

     // Get the current date and time
     LocalDateTime currentTime = LocalDateTime.now();
     System.out.println("Current DateTime: " + currentTime);
	
     LocalDate date1 = currentTime.toLocalDate();
     System.out.println("date1: " + date1);
	
     Month month = currentTime.getMonth();
     int day = currentTime.getDayOfMonth();
     int seconds = currentTime.getSecond();
	
     System.out.println("Month: " + month +"day: " + day +"seconds: " + seconds);
	
     LocalDateTime date2 = currentTime.withDayOfMonth(10).withYear(2012);
     System.out.println("date2: " + date2);
	
     //12 december 2014
     LocalDate date3 = LocalDate.of(2014, Month.DECEMBER, 12);
     System.out.println("date3: " + date3);
	
     //22 hour 15 minutes
     LocalTime date4 = LocalTime.of(22, 15);
     System.out.println("date4: " + date4);
	
     //parse a string
     LocalTime date5 = LocalTime.parse("20:15:30");
     System.out.println("date5: " + date5);
  }
 
Example 8
@Override
public void init(Display parent) {
	super.init(null); // The TitleScreen never has a parent.
	Renderer.readyToRenderGameplay = false;

	// check version
	checkVersion();

	/// this is useful to just ensure that everything is really reset as it should be. 
	if (Game.server != null) {
		if (Game.debug) System.out.println("wrapping up loose server ends");
		Game.server.endConnection();
		Game.server = null;
	}
	if (Game.client != null) {
		if (Game.debug) System.out.println("wrapping up loose client ends");
		Game.client.endConnection();
		Game.client = null;
	}
	Game.ISONLINE = false;

	LocalDateTime time = LocalDateTime.now();
	if (time.getMonth() == Month.DECEMBER) {
		if (time.getDayOfMonth() == 19) rand = 1;
		if (time.getDayOfMonth() == 25) rand = 2;
	} else {
		rand = random.nextInt(splashes.length - 3) + 3;
	}
	
	World.levels = new Level[World.levels.length];
	
	if(Game.player == null || Game.player instanceof RemotePlayer)
		// was online, need to reset player
		World.resetGame(false);
}
 
Example 9
Source Project: java8-tutorial   File: LocalDateTime1.java    License: MIT License 5 votes vote down vote up
public static void main(String[] args) {

        LocalDateTime sylvester = LocalDateTime.of(2014, Month.DECEMBER, 31, 23, 59, 59);

        DayOfWeek dayOfWeek = sylvester.getDayOfWeek();
        System.out.println(dayOfWeek);      // WEDNESDAY

        Month month = sylvester.getMonth();
        System.out.println(month);          // DECEMBER

        long minuteOfDay = sylvester.getLong(ChronoField.MINUTE_OF_DAY);
        System.out.println(minuteOfDay);    // 1439

        Instant instant = sylvester
                .atZone(ZoneId.systemDefault())
                .toInstant();

        Date legacyDate = Date.from(instant);
        System.out.println(legacyDate);     // Wed Dec 31 23:59:59 CET 2014


        DateTimeFormatter formatter =
                DateTimeFormatter
                        .ofPattern("MMM dd, yyyy - HH:mm");

        LocalDateTime parsed = LocalDateTime.parse("Nov 03, 2014 - 07:13", formatter);
        String string = parsed.format(formatter);
        System.out.println(string);     // Nov 03, 2014 - 07:13
    }
 
Example 10
private void setDefaultDates(ComAdmin admin, MailingStatisticForm form, Date mailingStartDate) {
    LocalDateTime mailingStart = LocalDateTime.now();
    LocalDateTime currentTime = LocalDateTime.now();

    int currentYear = currentTime.getYear();
    Month currentMonth = currentTime.getMonth();
    if (form.getMonth() == -1) {
        form.setMonth(currentMonth);
    }
    if (form.getYear() == 0) {
        form.setYear(currentYear);
    }

    if (mailingStartDate != null) {
        mailingStart = DateUtilities.toLocalDateTime(mailingStartDate, AgnUtils.getZoneId(admin));
    }
    
    SimpleDateFormat adminDateFormat = admin.getDateFormat();
    DateTimeFormatter dateFormatter = admin.getDateFormatter();

    DateMode dateMode = form.getDateMode();
    FormDateTime startDate = form.getStartDate();
    FormDateTime endDate = form.getEndDate();
    switch (dateMode) {
        case LAST_TENHOURS:
            startDate.set(mailingStart, dateFormatter);
            endDate.set(mailingStart.plusHours(10), dateFormatter);
            break;
        case SELECT_DAY:
            FormDateTime selectDay = form.getSelectDay();
            if(StringUtils.isBlank(selectDay.getDate())){
                selectDay.getFormDate().set(currentTime.toLocalDate(), dateFormatter);
            }

            Date selectDate = selectDay.get(adminDateFormat);
            startDate.set(selectDate, adminDateFormat);
            endDate.set(selectDate, adminDateFormat);
            break;
            
        case LAST_MONTH:
            startDate.getFormDate().set(currentTime.toLocalDate().with(firstDayOfMonth()), dateFormatter);
            endDate.getFormDate().set(currentTime.toLocalDate().with(lastDayOfMonth()), dateFormatter);
            break;
        case SELECT_MONTH:
            LocalDate selectedYear = currentTime.toLocalDate().withYear(form.getYear());
            LocalDate selectedMonth = selectedYear.withMonth(form.getMonthValue().getValue());
            startDate.getFormDate().set(selectedMonth.with(firstDayOfMonth()), dateFormatter);
            endDate.getFormDate().set(selectedMonth.with(lastDayOfMonth()), dateFormatter);
            break;
        case SELECT_PERIOD:
            if(StringUtils.isBlank(endDate.getDate())){
                endDate.getFormDate().set(currentTime.toLocalDate(), dateFormatter);
            }
            if(StringUtils.isBlank(startDate.getDate())){
                startDate.getFormDate().set(currentTime.toLocalDate().with(firstDayOfMonth()), dateFormatter);
            }
            break;
            default:
                //do nothing
    }
}