本文整理汇总了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) {
}
}