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


Java LocalTime類代碼示例

本文整理匯總了Java中org.joda.time.LocalTime的典型用法代碼示例。如果您正苦於以下問題:Java LocalTime類的具體用法?Java LocalTime怎麽用?Java LocalTime使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: TIME

import org.joda.time.LocalTime; //導入依賴的package包/類
public static String TIME(Integer hours, Integer minutes, Integer seconds, String timePattern){
	if(hours==null || minutes==null || seconds==null) {
		if(log.isDebugEnabled()){
			log.debug("None of the arguments can be null.");
		}
		return null;
	}
	LocalTime lt=new LocalTime(hours,minutes,seconds);
	if(timePattern==null) {
		return lt.toString(DateTimeFormat.longTime()); 
	}
	else{
		try{
			// Try to convert to a pattern
			DateTimeFormatter dtf = DateTimeFormat.forPattern(timePattern);
			return lt.toString(dtf);
		}
		catch (IllegalArgumentException ex){
			// Fallback to the default solution
			return lt.toString(DateTimeFormat.longTime()); 
		}			
	}
}
 
開發者ID:TIBCOSoftware,項目名稱:jasperreports,代碼行數:24,代碼來源:DateTimeFunctions.java

示例2: getDeadline

import org.joda.time.LocalTime; //導入依賴的package包/類
private DateTime getDeadline(LocalDate date) {
    Settings settings = settingsRepo.findById(1);
    int deadlineDays = settings.getDeadlineDays();
    LocalTime deadlineTime = settings.getDeadline();
     
    date = date.minusDays(deadlineDays);
    
    while (this.holidaysRepo.findByIdHoliday(date) != null) {
         date = date.minusDays(1);
    }        
    
    // Check if order deadline passed based on given date, deadlineDays and deadlineTime (deadline)
    //return (date.toLocalDateTime(deadlineTime).compareTo(LocalDateTime.now()) < 0);

    // When we ll change deadline time to utc, use this: 
    //return date.toLocalDateTime(deadlineTime).toDateTime(DateTimeZone.UTC);
    return date.toLocalDateTime(deadlineTime).toDateTime(); // To default zone
}
 
開發者ID:jrtechnologies,項目名稱:yum,代碼行數:19,代碼來源:MenusService.java

示例3: testDailyMenusIdPut_400_DailyMenuEntity_BadRequest

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void testDailyMenusIdPut_400_DailyMenuEntity_BadRequest() throws Exception
{
    mockFoodList.add(mockFood2);
    mockDailyMenu.setFoods(mockFoodList);
    mockDailyMenuList.add(mockDailyMenu);

    LocalTime deadline = new LocalTime(0, 0);
    Settings sets = new Settings(1, deadline, null, "€", "notes", "tos", "policy", 0, 0, "", "");
    given(mockSettingsRepository.findOne(1)).willReturn(sets);
    
    given(mockDailyMenuRepository.findById(6)).willReturn(mockDailyMenu);
    //given(mockHolidaysRepository.findByIdHoliday(new LocalDate(2017,04,28))).willReturn(null);
    
    mockMvc.perform(put("/api/dailyMenus/{id}", "6")
            .contentType(MediaType.APPLICATION_JSON_UTF8)
            .content("{}")
    ).andExpect(status().isBadRequest())
            .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));

}
 
開發者ID:jrtechnologies,項目名稱:yum,代碼行數:22,代碼來源:DailyMenusApiControllerTest.java

示例4: right

import org.joda.time.LocalTime; //導入依賴的package包/類
/**
 * 定義微信菜單
 */
@WxButton(group = WxButton.Group.RIGHT, main = true, name = "Hi")
public String right(WxUser wxUser) {
    log.info("wxUser:{}", wxUser);
    int hourOfDay = LocalTime.now().getHourOfDay();
    String wenhou;
    if (hourOfDay >= 7 && hourOfDay < 12) {
        wenhou = "上午好";
    } else if (hourOfDay == 12) {
        wenhou = "中午好";
    } else if (hourOfDay > 12 && hourOfDay < 19) {
        wenhou = "下午好";
    } else if (hourOfDay >= 19 && hourOfDay < 22) {
        wenhou = "晚上好";
    } else {
        wenhou = "太晚了。生活再忙,也要休息";
    }
    log.info("wenhou:{}", wenhou);
    return wxUser.getNickName() + "," + wenhou;
}
 
開發者ID:helloworldtang,項目名稱:sns-todo,代碼行數:23,代碼來源:WechatController.java

示例5: setUpTime

import org.joda.time.LocalTime; //導入依賴的package包/類
private void setUpTime() {
    mDisposableTaskDate.setText(DATE_FORMATTER.print(LocalDate.now()));
    mDisposableTaskTime.setText(TIME_FORMATTER.print(LocalTime.now()));
    if (mTimedTask == null) {
        mDailyTaskRadio.setChecked(true);
        return;
    }
    if (mTimedTask.isDisposable()) {
        mDisposableTaskRadio.setChecked(true);
        mDisposableTaskTime.setText(TIME_FORMATTER.print(mTimedTask.getMillis()));
        mDisposableTaskDate.setText(DATE_FORMATTER.print(mTimedTask.getMillis()));
        return;
    }
    LocalTime time = LocalTime.fromMillisOfDay(mTimedTask.getMillis());
    mDailyTaskTimePicker.setCurrentHour(time.getHourOfDay());
    mDailyTaskTimePicker.setCurrentMinute(time.getMinuteOfHour());
    if (mTimedTask.isDaily()) {
        mDailyTaskRadio.setChecked(true);
    } else {
        mWeeklyTaskRadio.setChecked(true);
        for (int i = 0; i < mDayOfWeekCheckBoxes.size(); i++) {
            mDayOfWeekCheckBoxes.get(i).setChecked(mTimedTask.hasDayOfWeek(i + 1));
        }
    }

}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:27,代碼來源:TimedTaskSettingActivity.java

示例6: createDisposableTask

import org.joda.time.LocalTime; //導入依賴的package包/類
private TimedTask createDisposableTask() {
    LocalTime time = TIME_FORMATTER.parseLocalTime(mDisposableTaskTime.getText().toString());
    LocalDate date = DATE_FORMATTER.parseLocalDate(mDisposableTaskDate.getText().toString());
    LocalDateTime dateTime = new LocalDateTime(date.getYear(), date.getMonthOfYear(), date.getDayOfMonth(),
            time.getHourOfDay(), time.getMinuteOfHour());
    if (dateTime.isBefore(LocalDateTime.now())) {
        Toast.makeText(this, R.string.text_disposable_task_time_before_now, Toast.LENGTH_SHORT).show();
        return null;
    }
    return TimedTask.disposableTask(dateTime, mScriptFile.getPath(), ExecutionConfig.getDefault());
}
 
開發者ID:hyb1996,項目名稱:Auto.js,代碼行數:12,代碼來源:TimedTaskSettingActivity.java

示例7: bind

import org.joda.time.LocalTime; //導入依賴的package包/類
private void bind(Station station) {
    StationFacilities facilities = station.getStationFacilities();
    StringBuilder openingHoursString = new StringBuilder();
    for (int i = 0; i < 7; i++) {
        LocalTime[] openingHours = facilities.getOpeningHours(i);
        if (openingHours == null) {
            openingHoursString.append("Closed");
        } else {
            openingHoursString.append(openingHours[0].toString("HH:mm")).append(" - ").append(openingHours[1].toString("HH:mm")).append("\n");
        }
    }
    ((TextView) findViewById(R.id.text_hours)).setText(openingHoursString.toString());
    ((TextView) findViewById(R.id.text_station)).setText(station.getLocalizedName());
    ((TextView) findViewById(R.id.text_address)).setText(String.format("%s %s %s", facilities.getStreet(), facilities.getZip(), facilities.getCity()));

    findViewById(R.id.image_tram).setVisibility(facilities.hasTram() ? View.VISIBLE : View.GONE);
    findViewById(R.id.image_bus).setVisibility(facilities.hasBus() ? View.VISIBLE : View.GONE);
    findViewById(R.id.image_subway).setVisibility(facilities.hasMetro() ? View.VISIBLE : View.GONE);

    // TODO: display information on accessibility
}
 
開發者ID:hyperrail,項目名稱:hyperrail-for-android,代碼行數:22,代碼來源:StationActivity.java

示例8: convert

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void convert() throws Exception {
    String dateString = "06/27/2017 12:30";
    DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
    Date date = df.parse(dateString);

    LocalTime localTime = (LocalTime) converter.convert(date, TypeToken.of(LocalTime.class));
    assertEquals(12, localTime.getHourOfDay());
    assertEquals(30, localTime.getMinuteOfHour());

    LocalDate localDate = (LocalDate) converter.convert(date, TypeToken.of(LocalDate.class));
    assertEquals(2017, localDate.getYear());
    assertEquals(6, localDate.getMonthOfYear());
    assertEquals(27, localDate.getDayOfMonth());

    LocalDateTime localDateTime = (LocalDateTime) converter.convert(date, TypeToken.of(LocalDateTime.class));
    assertEquals(12, localDateTime.getHourOfDay());
    assertEquals(30, localDateTime.getMinuteOfHour());
    assertEquals(2017, localDateTime.getYear());
    assertEquals(6, localDateTime.getMonthOfYear());
    assertEquals(27, localDateTime.getDayOfMonth());
}
 
開發者ID:keepcosmos,項目名稱:beanmother,代碼行數:23,代碼來源:DateToJodaTimeBaseLocalConverterTest.java

示例9: convert

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void convert() throws Exception {
    String dateString = "1985-09-03 13:30";

    LocalTime localTime = (LocalTime) converter.convert(dateString, TypeToken.of(LocalTime.class));
    assertEquals(13, localTime.getHourOfDay());
    assertEquals(30, localTime.getMinuteOfHour());

    LocalDate localDate = (LocalDate) converter.convert(dateString, TypeToken.of(LocalDate.class));
    assertEquals(1985, localDate.getYear());
    assertEquals(9, localDate.getMonthOfYear());
    assertEquals(3, localDate.getDayOfMonth());

    LocalDateTime localDateTime = (LocalDateTime) converter.convert(dateString, TypeToken.of(LocalDateTime.class));
    assertEquals(13, localDateTime.getHourOfDay());
    assertEquals(30, localDateTime.getMinuteOfHour());
    assertEquals(1985, localDateTime.getYear());
    assertEquals(9, localDateTime.getMonthOfYear());
    assertEquals(3, localDateTime.getDayOfMonth());
}
 
開發者ID:keepcosmos,項目名稱:beanmother,代碼行數:21,代碼來源:StringToJodaTimeBaseLocalConverterTest.java

示例10: testBasicMatch

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void testBasicMatch()
{
  TemplatedUtterance utterance = new TemplatedUtterance(tokenizer.tokenize("at {time}"));

  String[] input = tokenizer.tokenize("at 6:45am");
  Slots slots = new Slots();
  Context context = new Context();

  TimeSlot slot = new TimeSlot("time");
  slots.add(slot);

  TemplatedUtteranceMatch match = utterance.matches(input, slots, context);

  assertThat(match, is(notNullValue()));
  assertThat(match.isMatched(), is(true));
  assertThat(match.getSlotMatches().size(), is(1));

  SlotMatch slotMatch = match.getSlotMatches().get(slot);
  assertThat(slotMatch, is(notNullValue()));
  assertThat(slotMatch.getOrginalValue(), is("6:45am"));
  assertThat(slotMatch.getValue(), is(new LocalTime(6, 45)));
}
 
開發者ID:rabidgremlin,項目名稱:Mutters,代碼行數:24,代碼來源:TestTimeSlot.java

示例11: sumDeHours

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void sumDeHours()
{
    // Fixture Setup
    final LocalTime Hour1 = new LocalTime( 1, 12, 25 );
    final LocalTime Hour2 = new LocalTime( 2, 12, 25 );
    final LocalTime HourEsperada = new LocalTime( 3, 12, 25 );

    // Exercise SUT
    final int novaHour = Hour1.getHourOfDay() + Hour2.getHourOfDay();

    // Result Verification
    Assert.assertEquals( novaHour, HourEsperada.getHourOfDay() );

    // Fixture Teardown
}
 
開發者ID:evandrocoan,項目名稱:ComputerScienceGraduation,代碼行數:17,代碼來源:FirstClassJunitIndroduction.java

示例12: getHuntingDayInterval

import org.joda.time.LocalTime; //導入依賴的package包/類
/**
 * Converts given date and duration into a legal hunting day interval. Duration is rounded down
 * to half an hour resolution and, if needed, replaced with a legal default value in case a
 * value out of acceptable range is provided.
 */
@Nonnull
public static Interval getHuntingDayInterval(
        @Nonnull final LocalDate date, @Nullable final Float huntingDurationInHours) {

    Objects.requireNonNull(date, "date is null");

    final Float legalizedDuration = Optional.ofNullable(huntingDurationInHours)
            .filter(MooseDataCardHuntingDayField.HUNTING_DAY_DURATION::isValueInRange)
            .orElseGet(() -> Integer.valueOf(DEFAULT_DURATION).floatValue());

    final double durationRoundedDownToNearestHalfHour = roundDownToNearestHalfHour(legalizedDuration.doubleValue());
    final double durationRoundedToNearestHour = Math.ceil(durationRoundedDownToNearestHalfHour);

    final DateTime startTime = defaultStartTimeMustBeAdvanced(durationRoundedDownToNearestHalfHour)
            ? date.toDateTime(new LocalTime(
                    (int) (48.0 - durationRoundedToNearestHour),
                    (int) ((durationRoundedToNearestHour - durationRoundedDownToNearestHalfHour) * 60.0)))
            : date.toDateTime(DEFAULT_HUNTING_DAY_START_TIME);

    return new Interval(
            startTime.withZone(Constants.DEFAULT_TIMEZONE),
            startTime.plusMinutes((int) (durationRoundedDownToNearestHalfHour * 60.0))
                    .withZone(Constants.DEFAULT_TIMEZONE));
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:30,代碼來源:MooseDataCardExtractor.java

示例13: parsesJourneyDetails

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test
public void parsesJourneyDetails() throws IOException {
	try (InputStream is = getClass().getResourceAsStream("journeyDetails.json")) {
		JourneyDetailResponse response = sut.readValue(is, JourneyDetailResponse.class);
		Assert.assertEquals(6, response.getJourneyDetail().getStops().getStop().size());
		Assert.assertEquals(1, response.getJourneyDetail().getNames().getName().size());
		Assert.assertEquals(1, response.getJourneyDetail().getTypes().getType().size());
		Assert.assertEquals(1, response.getJourneyDetail().getOperators().getOperator().size());
		Assert.assertEquals(1, response.getJourneyDetail().getNotes().getNote().size());
		final Stop stop = response.getJourneyDetail().getStops().getStop().get(0);
		Assert.assertEquals("Frankfurt(Main)Hbf", stop.getName());
		Assert.assertEquals("8000105", stop.getId());
		Assert.assertEquals(8.663785, stop.getLon(), 0.000001);
		Assert.assertEquals(50.107149, stop.getLat(), 0.000001);
		Assert.assertEquals(LocalTime.parse("15:02"), stop.getDepTime());
		Assert.assertEquals(LocalDate.parse("2016-02-22"), stop.getDepDate());
		Assert.assertEquals(0, stop.getRouteIdx().intValue());
		Assert.assertEquals("13", stop.getTrack());
	}
}
 
開發者ID:highsource,項目名稱:db-fahrplan-api,代碼行數:21,代碼來源:ApiClientMapperTest.java

示例14: createHuntingDayDTO

import org.joda.time.LocalTime; //導入依賴的package包/類
private static GroupHuntingDayDTO createHuntingDayDTO(final HuntingClubGroup group, final boolean withHounds) {
    final GroupHuntingDayDTO dto = new GroupHuntingDayDTO();
    dto.setHuntingGroupId(group.getId());

    dto.setStartDate(today());
    dto.setEndDate(today());

    dto.setStartTime(LocalTime.now());
    dto.setEndTime(LocalTime.now().plusHours(1));

    dto.setBreakDurationInMinutes(10);
    dto.setNumberOfHunters(1);

    dto.setHuntingMethod(getAnyHuntingMethodByHounds(withHounds));
    return dto;
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:17,代碼來源:GroupHuntingDayCrudFeatureTest.java

示例15: testUpdateHarvest_whenSpeciesIsNotValid

import org.joda.time.LocalTime; //導入依賴的package包/類
@Test(expected = HarvestPermitSpeciesAmountNotFound.class)
public void testUpdateHarvest_whenSpeciesIsNotValid() {
    withPerson(author -> {
        final GameSpecies species = model().newGameSpecies(true);
        final Harvest harvest = model().newHarvest(species, author);
        final HarvestPermit permit = model().newHarvestPermit(true);
        final HarvestPermitSpeciesAmount amount = model().newHarvestPermitSpeciesAmount(permit, species);
        model().newHarvestReportFields(species, true);

        onSavedAndAuthenticated(createUser(author), () -> {

            invokeUpdateHarvest(create(harvest, 5)
                    .mutate()
                    .withPermitNumber(permit.getPermitNumber())
                    .withPointOfTime(amount.getBeginDate().minusDays(1).toLocalDateTime(LocalTime.MIDNIGHT))
                    .build());
        });
    });
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:20,代碼來源:GameDiaryFeatureTest.java


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