本文整理匯總了Java中org.joda.time.LocalTime.now方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalTime.now方法的具體用法?Java LocalTime.now怎麽用?Java LocalTime.now使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.joda.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.now方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: findCurrentLessonNo
import org.joda.time.LocalTime; //導入方法依賴的package包/類
private Optional<Integer> findCurrentLessonNo(List<LessonRange> ranges) {
LocalTime now = LocalTime.now();
for (int i = 0; i < ranges.size(); i++) {
LessonRange range = ranges.get(i);
if (!range.to().isPresent()) {
continue;
}
if (range.to().get().compareTo(now) > 0) {
return Optional.of(i);
}
}
return Optional.absent();
}
示例2: setLocation
import org.joda.time.LocalTime; //導入方法依賴的package包/類
public void setLocation(Location location, double qiblaAngle) {
if (location == null) return;
mPrayTimes.setCoordinates(location.getLatitude(), location.getLongitude(), 0);
mQiblaAngle = qiblaAngle;
mQiblaTime = mPrayTimes.getQiblaTime();
LocalTime sunrise = LocalTime.parse(mPrayTimes.getTime(Constants.TIMES_SUNRISE));
LocalTime sunset = LocalTime.parse(mPrayTimes.getTime(Constants.TIMES_SUNSET));
LocalTime current = LocalTime.now();
mShowSun = !(sunset.isBefore(current) || sunrise.isAfter(current));
mSunriseAngle = Math.toDegrees(getAzimuth(sunrise.toDateTimeToday().getMillis(), location.getLatitude(), location.getLongitude())) - qiblaAngle - 90;
mSunsetAngle = Math.toDegrees(getAzimuth(sunset.toDateTimeToday().getMillis(), location.getLatitude(), location.getLongitude())) - qiblaAngle - 90;
mCurrentAngle = Math.toDegrees(getAzimuth(current.toDateTimeToday().getMillis(), location.getLatitude(), location.getLongitude())) - qiblaAngle - 90;
}
示例3: isBreakOverMidnight
import org.joda.time.LocalTime; //導入方法依賴的package包/類
private boolean isBreakOverMidnight(TimeTrack timeTrack, Break breakToCheck) {
// if timeTrack is not over midnight, also break can't be over midnight
DateTime timeTrackStart = timeTrack.getFrom();
DateTime timeTrackEnd = timeTrack.getTo() == null ? DateTime.now() : timeTrack.getTo();
if(timeTrackEnd.isBefore(DateTimeUtils.endOfDay(timeTrackStart))) {
return false;
}
// but if timeTrack is over midnight, we have also to check break
LocalTime breakStart = breakToCheck.getFrom().toLocalTime();
LocalTime breakEnd = breakToCheck.getTo() == null ? LocalTime.now() : breakToCheck.getTo().toLocalTime();
if(breakStart.isBefore(breakEnd)) {
return false;
}
return true;
}
示例4: testGetRelativeDateTimeString
import org.joda.time.LocalTime; //導入方法依賴的package包/類
public void testGetRelativeDateTimeString() {
Context ctx = getInstrumentation().getContext();
assertEquals("0 seconds ago, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow, null, 0));
assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, 0));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, mNow.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, mNow.minusMinutes(30), null, 0));
assertEquals("in 3 hours, 15:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusHours(3), null, 0));
assertEquals("3 hours ago, 09:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusHours(3), null, 0));
assertEquals("Oct 25, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.plusDays(3), null, 0));
assertEquals("Oct 19, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, mNow.minusDays(3), null, 0));
// Test abbreviation
assertEquals("in 30 secs, 12:35",
DateUtils.getRelativeDateTimeString(ctx, mNow.plusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));
assertEquals("30 secs ago, 12:34",
DateUtils.getRelativeDateTimeString(ctx, mNow.minusSeconds(30), null, DateUtils.FORMAT_ABBREV_RELATIVE));
// Test transition resolution
DateTime dt = DateTime.now().plusDays(2);
assertEquals("in 2 days, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt, Days.TWO, 0));
assertEquals("Oct 24, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt.plusSeconds(1), Days.TWO, 0));
assertEquals("in 2 days, 12:35", DateUtils.getRelativeDateTimeString(ctx, dt, Days.THREE, 0));
// Test partial input
LocalTime lt = LocalTime.now();
assertEquals("in 30 seconds, 12:35", DateUtils.getRelativeDateTimeString(ctx, lt.plusSeconds(30), null, 0));
assertEquals("30 seconds ago, 12:34", DateUtils.getRelativeDateTimeString(ctx, lt.minusSeconds(30), null, 0));
assertEquals("in 30 minutes, 13:05", DateUtils.getRelativeDateTimeString(ctx, lt.plusMinutes(30), null, 0));
assertEquals("30 minutes ago, 12:05", DateUtils.getRelativeDateTimeString(ctx, lt.minusMinutes(30), null, 0));
// Test bad partial input
try {
assertEquals("Oct 24, 1995, 12:35", DateUtils.getRelativeDateTimeString(ctx, LocalDate.now(), null, 0));
fail("DateUtils.getRelativeDateTimeString() should have thrown an error since LocalDate has no time.");
}
catch (Exception e) {
}
}