本文整理汇总了Java中java.time.LocalTime.plusHours方法的典型用法代码示例。如果您正苦于以下问题:Java LocalTime.plusHours方法的具体用法?Java LocalTime.plusHours怎么用?Java LocalTime.plusHours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.plusHours方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test_plusHours_fromZero
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromZero() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.MIDNIGHT);
LocalDate d = base.toLocalDate().minusDays(3);
LocalTime t = LocalTime.of(21, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.plusHours(i);
t = t.plusHours(1);
if (t.getHour() == 0) {
d = d.plusDays(1);
}
assertEquals(dt.toLocalDate(), d);
assertEquals(dt.toLocalTime(), t);
}
}
示例2: testSplitLocalTime
import java.time.LocalTime; //导入方法依赖的package包/类
@Test(dataProvider = "directions")
public void testSplitLocalTime(boolean ascending) {
final Duration step = Duration.ofMillis(1);
final LocalTime start = ascending ? LocalTime.of(9, 0) : LocalTime.of(17, 0);
final LocalTime end = ascending ? start.plusHours(8) : start.minusHours(8);
final Range<LocalTime> range = Range.of(start, end, step);
final List<Range<LocalTime>> segments = range.split(100);
Assert.assertTrue(segments.size() > 1, "There are multiple segments");
for (int i=1; i<segments.size(); ++i) {
final Range<LocalTime> prior = segments.get(i-1);
final Range<LocalTime> next = segments.get(i);
Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
if (i == segments.size()-1) {
Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
}
}
}
示例3: createEntries
import java.time.LocalTime; //导入方法依赖的package包/类
private void createEntries(LocalDate startDate) {
for (int j = 0; j < 5 + (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(startDate);
entry.changeEndDate(startDate);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
entry.setCalendar(this);
}
}
示例4: test_plusHours_fromOne
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromOne() {
LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
LocalDate d = base.toLocalDate().minusDays(3);
LocalTime t = LocalTime.of(22, 0);
for (int i = -50; i < 50; i++) {
LocalDateTime dt = base.plusHours(i);
t = t.plusHours(1);
if (t.getHour() == 0) {
d = d.plusDays(1);
}
assertEquals(dt.toLocalDate(), d);
assertEquals(dt.toLocalTime(), t);
}
}
示例5: createEntries
import java.time.LocalTime; //导入方法依赖的package包/类
private void createEntries(YearMonth month) {
for (int i = 1; i < 28; i++) {
LocalDate date = month.atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例6: HelloCalendar
import java.time.LocalTime; //导入方法依赖的package包/类
public HelloCalendar() {
for (Month month : Month.values()) {
YearMonth yearMonth = YearMonth.of(LocalDate.now().getYear(), month);
for (int i = 1; i < 28; i++) {
LocalDate date = yearMonth.atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime
.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
}
示例7: HelloCalendar
import java.time.LocalTime; //导入方法依赖的package包/类
public HelloCalendar() {
LocalDate date = LocalDate.now();
for (int i = 1; i < 3; i++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + i);
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .1) {
entry.setFullDay(true);
entry.setTitle("Full Day Entry");
}
entry.setCalendar(this);
}
}
示例8: createEntries
import java.time.LocalTime; //导入方法依赖的package包/类
private void createEntries(YearMonth month) {
for (int i = 1; i < 28; i++) {
LocalDate date = month.atDay(i);
for (int j = 0; j < (int) (Math.random() * 2); j++) {
Entry<?> entry = new Entry<>();
entry.setTitle("Entry " + (j + 1));
LocalDate startDate = date;
LocalDate endDate = startDate.plusDays((int) (Math.random() * 4));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(23 - hour, (int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.setInterval(startDate, startTime, endDate, endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例9: HelloCalendar
import java.time.LocalTime; //导入方法依赖的package包/类
public HelloCalendar() {
for (int i = 1; i < 28; i++) {
LocalDate date = YearMonth.now().atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date.plusDays((int) (Math.random() * 4)));
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例10: HelloCalendar
import java.time.LocalTime; //导入方法依赖的package包/类
public HelloCalendar(Year year) {
for (int i = 1; i < 365; i++) {
LocalDate date = year.atDay(i);
for (int j = 0; j < (int) (Math.random() * 4); j++) {
Entry<?> entry = new Entry<>();
entry.changeStartDate(date);
entry.changeEndDate(date);
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 23);
int durationInHours = Math.min(24 - hour, (int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.changeStartTime(startTime);
entry.changeEndTime(endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例11: createEntries
import java.time.LocalTime; //导入方法依赖的package包/类
private void createEntries(YearMonth month) {
for (int i = 1; i < 28; i++) {
LocalDate date = month.atDay(i);
for (int j = 0; j < (int) (Math.random() * 7); j++) {
Entry<?> entry = new Entry<>();
entry.setTitle("Entry " + (j + 1));
int hour = (int) (Math.random() * 22);
int durationInHours = Math.min(24 - hour,
(int) (Math.random() * 4));
LocalTime startTime = LocalTime.of(hour, 0);
LocalTime endTime = startTime.plusHours(durationInHours);
entry.setInterval(date, startTime, date.plusDays((int) (Math.random() * 4)), endTime);
if (Math.random() < .3) {
entry.setFullDay(true);
}
entry.setCalendar(this);
}
}
}
示例12: test_plusHours_fromZero
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromZero() {
LocalTime base = LocalTime.MIDNIGHT;
for (int i = -50; i < 50; i++) {
LocalTime t = base.plusHours(i);
assertEquals(t.getHour(), (i + 72) % 24);
}
}
示例13: TimeScaleViewSkin
import java.time.LocalTime; //导入方法依赖的package包/类
public TimeScaleViewSkin(T view) {
super(view);
LocalTime time = LocalTime.of(1, 0);
for (int i = 1; i < 24; i++) {
Label label = new Label(time.format(formatter));
label.setManaged(false);
label.setMaxWidth(Double.MAX_VALUE);
label.setAlignment(Pos.CENTER_RIGHT);
label.getStyleClass().add("time-label"); //$NON-NLS-1$
label.setTextOverrun(OverrunStyle.CLIP);
labels.add(label);
getChildren().add(label);
time = time.plusHours(1);
}
currentTimeLabel = new Label();
currentTimeLabel.getStyleClass().add("current-time-label"); //$NON-NLS-1$
currentTimeLabel.setManaged(false);
currentTimeLabel.setMaxWidth(Double.MAX_VALUE);
currentTimeLabel.setAlignment(Pos.CENTER_RIGHT);
currentTimeLabel.setOpacity(0);
currentTimeLabel.setTextOverrun(OverrunStyle.CLIP);
currentTimeLabel.visibleProperty().bind(view.enableCurrentTimeMarkerProperty());
getChildren().add(currentTimeLabel);
updateCurrentTimeMarkerVisibility();
view.showCurrentTimeMarkerProperty().addListener(
it -> updateCurrentTimeMarkerVisibility());
setupCurrentTimeMarkerSupport();
updateShowMarkers();
}
示例14: test_plusHours_one
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_one() {
LocalTime t = LocalTime.MIDNIGHT;
for (int i = 0; i < 50; i++) {
t = t.plusHours(1);
assertEquals(t.getHour(), (i + 1) % 24);
}
}
示例15: test_plusHours_fromOne
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void test_plusHours_fromOne() {
LocalTime base = LocalTime.of(1, 0);
for (int i = -50; i < 50; i++) {
LocalTime t = base.plusHours(i);
assertEquals(t.getHour(), (1 + i + 72) % 24);
}
}