小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

使用java的Calendar對(duì)象獲得當(dāng)前日期

 Mis林桑 2017-03-25

      本文給大家分享的是使用使用java的Calendar對(duì)象獲得當(dāng)前日期的上幾個(gè)度開始、結(jié)束時(shí)間,主要思路是先獲得當(dāng)前季度的開始和結(jié)束日期,在當(dāng)前日期的基礎(chǔ)上往前推3個(gè)月即上個(gè)季度的開始和結(jié)束日期,十分的實(shí)用,小伙伴們可以參考下。

      思路:

      先獲得當(dāng)前季度的開始和結(jié)束日期,在當(dāng)前日期的基礎(chǔ)上往前推3個(gè)月即上個(gè)季度的開始和結(jié)束日期

      /** 

      * @param flag true:開始日期;false:結(jié)束日期 

      * @return 

      */

      public static String getLastQuarterTime(boolean flag){ 

      SimpleDateFormat shortSdf = new SimpleDateFormat('yyyy-MM-dd'); 

      SimpleDateFormat longSdf = new SimpleDateFormat('yyyy-MM-dd HH:mm:ss'); 

      String resultDate=''; 

      Date now = null; 

      try { 

      Calendar calendar = Calendar.getInstance(); 

      int currentMonth = calendar.get(Calendar.MONTH) + 1; 

      //true:開始日期;false:結(jié)束日期 

      if(flag){ 

      if (currentMonth >= 1 && currentMonth <= 3) 

      calendar.set(Calendar.MONTH, 0); 

      else if (currentMonth >= 4 && currentMonth <= 6) 

      calendar.set(Calendar.MONTH, 3); 

      else if (currentMonth >= 7 && currentMonth <= 9) 

      calendar.set(Calendar.MONTH, 6); 

      else if (currentMonth >= 10 && currentMonth <= 12) 

      calendar.set(Calendar.MONTH, 9); 

      calendar.set(Calendar.DATE, 1); 

      now = longSdf.parse(shortSdf.format(calendar.getTime()) + ' 00:00:00'); 

      }else{ 

      if (currentMonth >= 1 && currentMonth <= 3) { 

      calendar.set(Calendar.MONTH, 2); 

      calendar.set(Calendar.DATE, 31); 

      } else if (currentMonth >= 4 && currentMonth <= 6) { 

      calendar.set(Calendar.MONTH, 5); 

      calendar.set(Calendar.DATE, 30); 

      } else if (currentMonth >= 7 && currentMonth <= 9) { 

      calendar.set(Calendar.MONTH, 8); 

      calendar.set(Calendar.DATE, 30); 

      } else if (currentMonth >= 10 && currentMonth <= 12) { 

      calendar.set(Calendar.MONTH, 11); 

      calendar.set(Calendar.DATE, 31); 

      } 

      now = longSdf.parse(shortSdf.format(calendar.getTime()) + ' 23:59:59'); 

      } 

      calendar.setTime(now);// 設(shè)置日期 

      calendar.add(Calendar.MONTH, -3); 

      resultDate = longSdf.format(calendar.getTime()); 

      } catch (Exception e) { 

      ; 

      } 

      return resultDate; 

      } 

      文章來源:http://www./article.php?CID=26&ID=677

      了解更多內(nèi)容可登錄中軟國際官方網(wǎng)站:www.

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約