本文整理汇总了Java中java.time.LocalTime.now方法的典型用法代码示例。如果您正苦于以下问题:Java LocalTime.now方法的具体用法?Java LocalTime.now怎么用?Java LocalTime.now使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.time.LocalTime
的用法示例。
在下文中一共展示了LocalTime.now方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EditorDialog
import java.time.LocalTime; //导入方法依赖的package包/类
/**
* Instantiates a new Editor dialog.
*/
public EditorDialog() {
this.showedTime = LocalTime.now();
container = new VBox();
container.setAlignment(CENTER);
final EditorConfig editorConfig = EditorConfig.getInstance();
final CssColorTheme theme = editorConfig.getTheme();
final Scene scene = new Scene(container);
final ObservableList<String> stylesheets = scene.getStylesheets();
stylesheets.addAll(CSS_REGISTRY.getAvailableCssFiles());
stylesheets.add(theme.getCssFile());
createControls(container);
dialog = new Stage();
dialog.setTitle(getTitleText());
dialog.initStyle(StageStyle.UTILITY);
dialog.initModality(Modality.WINDOW_MODAL);
dialog.setResizable(isResizable());
dialog.setScene(scene);
configureSize(container);
}
示例2: submit
import java.time.LocalTime; //导入方法依赖的package包/类
public void submit(Config config, Runnable command){
if (appsHashMap.containsKey(config)){
log.info("App: {} already monitored", config);
return;
}
String[] strategy = config.getStrategy();
Future result=null;
switch (strategy[0]){
case "replay":
result = scheduleAtFixedRate(command,0, Long.parseLong(strategy[1]),TimeUnit.SECONDS);
break;
case "fixed":
String[] spliteTime = strategy[1].split(":");
LocalTime scheduledTime = LocalTime.of(Integer.parseInt(spliteTime[0]),Integer.parseInt(spliteTime[1]));
LocalTime now = LocalTime.now();
long delay = Duration.between(now,scheduledTime).getSeconds();
result = scheduleAtFixedRate(command,delay>0?delay:24*60*60+delay, 24*60*60L,TimeUnit.SECONDS);
break;
default: break;
}
appsHashMap.put(config,result);
log.debug("task account:{}",super.getTaskCount());
log.debug("task active account:{}",super.getActiveCount());
log.debug("task complete account:{}",super.getCompletedTaskCount());
}
示例3: main
import java.time.LocalTime; //导入方法依赖的package包/类
public static void main(String[] args) {
// Hours, minutes
LocalTime timeHrsMin = LocalTime.of(12, 12);
// Hours, minutes and seconds
LocalTime timeHrsMinSec = LocalTime.of(0, 12, 6);
// Hours, minutes, seconds and nanoseconds
LocalTime timeHrsMinSecNano = LocalTime.of(14, 7, 10, 998654578);
// DateTimeException
//LocalTime timeHrsMin1 = LocalTime.of(120, 12);// Runtime exception
//LocalTime timeHrsMin2 = LocalTime.of(9986545781, 12);// Compilation error
// To get the current time from the system clock, use the static method now()
LocalTime date3 = LocalTime.now();
// Parse a string to instantiate LocalTime by using its static method parse()
LocalTime time = LocalTime.parse("15:08:23");
}
示例4: shouldChangeInterval
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void shouldChangeInterval() {
LocalDate startDate = LocalDate.now().plusDays(1);
LocalDate endDate = LocalDate.now().plusDays(2);
LocalTime startTime = LocalTime.now();
LocalTime endTime = LocalTime.now().plusHours(10);
Interval interval = new Interval(startDate, startTime, endDate, endTime,
ZoneId.of("UTC"));
entry.setInterval(interval);
assertThat(entry.getStartDate(), is(equalTo(startDate)));
assertThat(entry.getStartTime(), is(equalTo(startTime)));
assertThat(entry.getEndDate(), is(equalTo(endDate)));
assertThat(entry.getEndTime(), is(equalTo(endTime)));
assertThat(entry.getZoneId(), is(equalTo(ZoneId.of("UTC"))));
}
示例5: main
import java.time.LocalTime; //导入方法依赖的package包/类
/**
* 程序执行入口.
*
* @param args 命令行参数
*/
public static void main(String[] args) {
LocalTime time = LocalTime.now();// |\longremark{获取当前时间}|
System.out.println("Current Time=" + time);
LocalTime specificTime = LocalTime.of(12, 20, 25, 40); // |\longremark{根据给定时间创建时间对象}|
System.out.println("Specific Time of Day=" + specificTime);
LocalTime timeShanghai = LocalTime.now(ZoneId.of("Asia/Shanghai")); // |\longremark{根据给定时区创建时间对象}|
System.out.println("Current Time in CST=" + timeShanghai);
//Getting date from the base date i.e 01/01/1970
LocalTime specificSecondTime = LocalTime.ofSecondOfDay(10000);// |\longremark{获得从1970-1-1开始计算的时间}|
System.out.println("10000th second time= " + specificSecondTime);
LocalTime one = LocalTime.parse("12:30:55"); //|\longremark{将字符串解析为LocalTime对象}|
LocalTime two = LocalTime.parse("13:02:15");
//LocalTime three = LocalTime.parse("2016-1-1 13:02:15"); // 格式错误
System.out.println("12:30:55 parsed to LocalDate = " + one);
System.out.println("12:30:55 < 13:02:15 ? " + one.isBefore(two));
System.out.println("12:30:55 < 12:30:55 ? " + one.isBefore(one));
System.out.println("13:02:15 > 12:30:55 ? " + two.isAfter(one));
}
示例6: setLocalTime
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void setLocalTime() {
final LocalTime value = LocalTime.now();
final Iterator<Value<?>> it = ps.setLocalTime(value).params().iterator();
assertEquals(new LocalTimeValue(value), it.next());
assertFalse(it.hasNext());
}
示例7: setLocalTimePositional
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void setLocalTimePositional() {
final LocalTime value = LocalTime.now();
final Iterator<Value<?>> it = ps.setLocalTime(0, value).params().iterator();
assertEquals(new LocalTimeValue(value), it.next());
assertFalse(it.hasNext());
}
示例8: now_ZoneId
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
LocalTime expected = LocalTime.now(Clock.system(zone));
LocalTime test = LocalTime.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = LocalTime.now(Clock.system(zone));
test = LocalTime.now(zone);
}
assertEquals(test, expected);
}
示例9: actionPerformed
import java.time.LocalTime; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {
LocalTime localeTime = LocalTime.now();
int hour = localeTime.getHour();
int minute = localeTime.getMinute();
int second = localeTime.getSecond();
timeText.setText(String.format("%02d : %02d : %02d", hour, minute, second));
}
示例10: accept
import java.time.LocalTime; //导入方法依赖的package包/类
@Override
public boolean accept(Media candidate) {
LocalTime now = LocalTime.now(clock);
if (begin.isBefore(stop)) {
return logAndReturn(begin.isBefore(now) && now.isBefore(stop), now);
} else {
return logAndReturn((
now.isAfter(begin) && now.isAfter(stop)) || (now.isBefore(stop) && now.isBefore(begin)), now);
}
}
示例11: shouldFailBecauseOfBadDates
import java.time.LocalTime; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void shouldFailBecauseOfBadDates() {
// given
LocalDate startDate = LocalDate.now();
LocalDate endDate = LocalDate.now().minusDays(1);
// when
new Interval(startDate, LocalTime.now(), endDate, LocalTime.now(), ZoneId.systemDefault());
// then
// throw exception
}
示例12: shouldFailBecauseOfBadTimes
import java.time.LocalTime; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void shouldFailBecauseOfBadTimes() {
// given
LocalDate startDate = LocalDate.now();
LocalDate endDate = startDate;
// when
new Interval(startDate, LocalTime.now(), endDate, LocalTime.now().minusHours(1), ZoneId.systemDefault());
// then
// throw exception
}
示例13: now_Clock_min
import java.time.LocalTime; //导入方法依赖的package包/类
@Test
public void now_Clock_min() {
Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
LocalTime test = LocalTime.now(clock);
assertEquals(test.getHour(), 0);
assertEquals(test.getMinute(), 0);
assertEquals(test.getSecond(), 0);
assertEquals(test.getNano(), 0);
}
示例14: notifyShowed
import java.time.LocalTime; //导入方法依赖的package包/类
@Override
@FXThread
public void notifyShowed() {
this.showedTime = LocalTime.now();
final EditorDescription description = getDescription();
GAnalytics.sendPageView(description.getEditorId(), null, "/editing/" + description.getEditorId());
}
示例15: openFile
import java.time.LocalTime; //导入方法依赖的package包/类
@Override
@FXThread
public void openFile(@NotNull final Path file) {
FX_EVENT_MANAGER.addEventHandler(FileChangedEvent.EVENT_TYPE, getFileChangedHandler());
this.file = file;
this.showedTime = LocalTime.now();
final EditorDescription description = getDescription();
GAnalytics.sendEvent(GAEvent.Category.EDITOR, GAEvent.Action.EDITOR_OPENED,
description.getEditorId() + "/" + getFileName());
GAnalytics.sendPageView(description.getEditorId(), null, "/editing/" + description.getEditorId());
}