close

如何將DatePicker的日期或月份往前預設

private DatePicker Date;

Date.setValue(LocalDate.now().plusMonths(-2));

 

 如何去掉字串頭尾的空格

用於資料存儲時篩選用

String aaa=" abc ";

aaa=aaa..trim();

 

如何將String字串轉換為LocalDateTime格式

DP_Date.setValue(LocalDate.parse(2017-07-30));

參考資料:

https://gxnotes.com/article/77983.html

https://www.mkyong.com/java8/java-8-how-to-convert-string-to-localdate/

 

 

 

將日期元件相關的LocalDateTime.now()轉換為Timestamp以存儲進資料庫

/*將 LocalDateTime.now() 轉換為 Timestamp */

final Timestamp timestampNow = Timestamp.valueOf(LocalDateTime.now());

/*將Tc021的值轉換為 LocalDateTime.now() 再轉換為 Timestamp */
final Timestamp createTime = Timestamp.valueOf(LocalDateTime.parse(item.getTc21()));

 

將資料庫日期以Timestamp格式取出後以LocalDateTime在元件中操作

String timeNow = record.getValue(16, Timestamp.class).toLocalDateTime().toString();

 

日期處理參考資料

可以判斷星期幾

http://www.jianshu.com/p/2949db9c3df5

timestamp映射資料參考

https://www.liaoxuefeng.com/article/00141939241051502ada88137694b62bfe844cd79e12c32000

民國/西元轉換

http://samchu.logdown.com/posts/285725-jdk8-date-time

timestamp在SQL語法跟程式中運算方式

https://www.javaworld.com.tw/jute/post/view?bid=29&id=235722&sty=0&tpg=2&ppg=1&age=0

在MySql語法中運算時間

http://fanli7.net/a/shujuku/Mysql/20110525/86764.html

在資料庫(SQL)中運算時間差

http://blog.csdn.net/u010963948/article/details/53230054

 

日期處理參考資料-時間格式手動運算-將毫秒long轉回時分秒

https://my.oschina.net/u/347158/blog/300278

 

日期處理參考資料-JAVA.unit.Calendar運算時間-將毫秒long轉回時分秒

/*計算時間差*/
    private void Length_Of_Time(Timestamp firstTime,Timestamp SecondTime) {
        
        /*將timestamp轉換為毫秒long*/
        long first_l = firstTime.getTime();
        long second_l = SecondTime.getTime();
        /*計算時間差,單位毫秒*/
        long answer_l=second_l-first_l;
        

        /*NOTE 將毫秒long透過Calendar來轉換為時間*/
        Calendar cal = Calendar.getInstance();
        cal.setTimeZone(TimeZone.getTimeZone("UTC"));
        cal.setTimeInMillis(answer_l);
        String curTime = String.format("%02d:%02d:%02d", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
        
        /*手動-檢查時間是否正確*/
        System.out.println("curTime="+curTime);
        // TODO Auto-generated method stub
        
    }

參考資料-基本用法

https://stackoverflow.com/questions/7487460/java-convert-long-to-date

參考資料-格式化用法

https://stackoverflow.com/questions/6782185/convert-timestamp-long-to-normal-date-format
 


                   

如何將TextArea的資料一行一行讀取

/*TextArea名子為textMemo*/

String[] lines;
         lines=textMemo.getText().split("\n");
         for(int i=0;i<lines.length;i++){
             System.out.println(lines[i]+"---ddf");
         }

參考資料:http://www.debugease.com/j2se/1227243.html

 

 

 

arrow
arrow
    全站熱搜

    蓋瑞修特 發表在 痞客邦 留言(1) 人氣()