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


Java LocalTime.now方法代碼示例

本文整理匯總了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);
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:29,代碼來源:EditorDialog.java

示例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());
}
 
開發者ID:huang-kai,項目名稱:auto-scale-java,代碼行數:26,代碼來源:TaskScheduledThreadPool.java

示例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");


}
 
開發者ID:huby,項目名稱:java-se8-oca-study-guide,代碼行數:21,代碼來源:Main.java

示例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"))));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:20,代碼來源:EntryTest.java

示例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));
}
 
開發者ID:subaochen,項目名稱:java-tutorial,代碼行數:29,代碼來源:LocalTimeTest.java

示例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());
}
 
開發者ID:traneio,項目名稱:ndbc,代碼行數:8,代碼來源:PreparedStatementTest.java

示例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());
}
 
開發者ID:traneio,項目名稱:ndbc,代碼行數:8,代碼來源:PreparedStatementTest.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:15,代碼來源:TCKLocalTime.java

示例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));
}
 
開發者ID:AitorB,項目名稱:POPBL_V,代碼行數:11,代碼來源:Time.java

示例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);
    }
}
 
開發者ID:ccremer,項目名稱:clustercode,代碼行數:11,代碼來源:TimeConstraint.java

示例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
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:13,代碼來源:IntervalTest.java

示例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
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:13,代碼來源:IntervalTest.java

示例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);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TCKLocalTime.java

示例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());
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:9,代碼來源:AbstractFileEditor.java

示例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());
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:16,代碼來源:AbstractFileEditor.java


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