後,我想創建成癮日期值的一些數據小GUI。所以我正在使用JavaFX中的LocalDateTimeTextField
。所以我會選擇的時間用下面的代碼:JavaFX的設置自然而然最終LocalDateTime選擇啓動LocalDateTime
LocalDateTimeTextField tend;
LocalDateTimeTextField tbegin;
String en = tend.getLocalDateTime().withSecond(0).toString();
String ende = en.replaceAll("T", " ");
String endezeit = ende.substring(11, 16);
String be = tbegin.getLocalDateTime().withSecond(0).toString();
String begin = be.replaceAll("T", " ");
String beginzeit = begin.substring(11, 16);
String datum = begin.substring(0, 10);
由於輸出我會得到:
System.out.println("Beginn: "+datum + " " + beginzeit);
System.out.println("Ende: "+datum + " " + endezeit);
初學者:2017年3月8日00:00
恩德:2017- 03-08 23:59
因此,爲了獲得開始和結束的時間,我必須手動選擇兩個日期。
有沒有一種解決方案,已選定的開始時間後,自動生成一個給定的結束時間,例如1小時?因此,我不需要編輯「時報」的「工作」,最好的情況下只需選擇一個日期。
謝謝您的建議!噹噹做工精細:)
LocalDateTime timebegin = tbegin.getLocalDateTime().withSecond(0);
LocalDateTime timeend = timebegin.plusHours(23).plusMinutes(59).plusSeconds(59);
LocalDate datum = timebegin.toLocalDate();
LocalTime start = timebegin.toLocalTime().plusSeconds(0);
LocalTime ende = timeend.toLocalTime();
tend.setLocalDateTime(timeend);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
但現在我知道,我的問題是不正確的措辭,因爲我還是想改變結束日期tend
在應用程序中。但是沒有機會,因爲它是固定在23:59:在tbegin
後59H。但我的想法是設置tbegin
與日期自動設置tend
到23:59:59H後,但也可能改變爲10:00:00H後。但是也許我必須創建一個Button,它可以完成這些臨時步驟。可以這麼理解,我想要的,這裏的一些圖片:
所以應該給我場與結束日期,我點擊該按鈕之前。而且應該可以將enddate編輯爲其他日期/時間。
謝謝你的幫助:)我從來沒有真正意識到格式化的事實:)非常感謝!現在我已經更新了我的問題,並帶有一個新舊問題:D – Franky