久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      java中將string轉(zhuǎn)為date的方法有哪些

      轉(zhuǎn)換方法:1、使用SimpleDateFormat來(lái)格式化時(shí)間;2、使用“org.apache.commons.lang3.time.DateUtils”來(lái)格式化時(shí)間;3、使用DateTimeFormatter來(lái)格式化時(shí)間。

      java中將string轉(zhuǎn)為date的方法有哪些

      本教程操作環(huán)境:windows7系統(tǒng)、java8版、DELL G3電腦。

      String轉(zhuǎn)Date常見三種方式:SimpleDateFormat、org.apache.commons.lang3.time.DateUtils、DateTimeFormatter(Java 8)

      描述
      SimpleDateFormat 線程不安全、文本匹配靈活

      DateUtils

      工具類、支持日期運(yùn)算
      DateTimeFormatter

      線程安全、配合LocalDateTime支持鏈?zhǔn)骄幊獭⒎奖惚容^運(yùn)算

      下面為示例代碼

      /**      *     指定當(dāng)前時(shí)間-指定時(shí)間是否大于30秒      */          //SimpleDateFormat     private static void m1() throws ParseException {         String endTime = "哈哈2020-02-07 18:58:02.0你好";//支持特殊格式轉(zhuǎn)換         String format = "哈哈yyyy-MM-dd HH:mm:ss";         SimpleDateFormat sdf = new SimpleDateFormat(format);         Date edate = sdf.parse(endTime);         Date now = new Date();         String nowStr = DateFormatUtils.format(now, format);         if(DateUtils.addSeconds(edate, 30).before((now))){             logger.info("true endTime={} now={}",endTime, nowStr);         }else{             logger.info("false endTime={} now={}",endTime, nowStr);         }     }      //DateUtils     private static void m3() throws ParseException {         String endTime = "2020-02-07 18:58:02.0";         String format = "yyyy-MM-dd HH:mm:ss";         Date edate = DateUtils.parseDate(endTime, format, "yyyy-MM-dd HH:mm:ss.SSS");//支持多格式匹配         Date now = new Date();         String nowStr = DateFormatUtils.format(now, format);         if(DateUtils.addSeconds(edate, 30).before((now))){             logger.info("true endTime={} now={}",endTime, nowStr);         }else{             logger.info("false endTime={} now={}",endTime, nowStr);         }     }      //DateTimeFormatter     private static void m2(){         String endTime = "2020-02-07 18:58:02";         String format = "yyyy-MM-dd HH:mm:ss";         LocalDateTime now = LocalDateTime.now();         DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);         String nowStr = now.format(dateTimeFormatter);         if(LocalDateTime.parse(endTime, dateTimeFormatter)                 .plusSeconds(30).isBefore(LocalDateTime.now())){//鏈?zhǔn)骄幊?            logger.info("true endTime={} now={}",endTime, nowStr);         }else{             logger.info("false endTime={} now={}",endTime, nowStr);         }     }

      相關(guān)視頻教程推薦:Java視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)