最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

思路:

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

/**
   * @param flag true:開(kāi)始日期;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:開(kāi)始日期;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;
  }

相關(guān)文章

  • Spring?Boot?優(yōu)雅整合多數(shù)據(jù)源

    Spring?Boot?優(yōu)雅整合多數(shù)據(jù)源

    這篇文章主要介紹了Spring?Boot?優(yōu)雅整合多數(shù)據(jù)源,多數(shù)據(jù)源就是在一個(gè)單一應(yīng)用中涉及到了兩個(gè)及以上的數(shù)據(jù)庫(kù),更多相關(guān)內(nèi)容需要的小伙伴可以參考下面文章介紹
    2022-05-05
  • IDEA?設(shè)置?SpringBoot?logback?彩色日志的解決方法?附配置文件

    IDEA?設(shè)置?SpringBoot?logback?彩色日志的解決方法?附配置文件

    這篇文章主要介紹了IDEA?設(shè)置?SpringBoot?logback?彩色日志(附配置文件)的操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-12-12
  • Java8時(shí)間api之LocalDate/LocalDateTime的用法詳解

    Java8時(shí)間api之LocalDate/LocalDateTime的用法詳解

    在項(xiàng)目中,時(shí)間的使用必不可少,而java8之前的時(shí)間api?Date和Calander等在使用上存在著很多問(wèn)題,于是,jdk1.8引進(jìn)了新的時(shí)間api-LocalDateTime,本文就來(lái)講講它的具體使用吧
    2023-05-05
  • 如何通過(guò)java獲取文件名和擴(kuò)展名

    如何通過(guò)java獲取文件名和擴(kuò)展名

    這篇文章主要介紹了如何通過(guò)java獲取文件名和擴(kuò)展名,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-01-01
  • SpringBoot詳解實(shí)現(xiàn)自定義異常處理頁(yè)面方法

    SpringBoot詳解實(shí)現(xiàn)自定義異常處理頁(yè)面方法

    SpringBoot是Spring全家桶的成員之一,是一種整合Spring技術(shù)棧的方式(或者說(shuō)是框架),同時(shí)也是簡(jiǎn)化Spring的一種快速開(kāi)發(fā)的腳手架
    2022-06-06
  • 華為技術(shù)專(zhuān)家講解JVM內(nèi)存模型(收藏)

    華為技術(shù)專(zhuān)家講解JVM內(nèi)存模型(收藏)

    這篇文章主要介紹了華為技術(shù)專(zhuān)家講解JVM內(nèi)存模型(收藏)的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的收藏借鑒價(jià)值,需要的朋友可以參考下
    2021-05-05
  • SpringBoot之RabbitMQ的使用方法

    SpringBoot之RabbitMQ的使用方法

    這篇文章主要介紹了SpringBoot之RabbitMQ的使用方法,詳細(xì)的介紹了2種模式,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-12-12
  • Spring Cache手動(dòng)清理Redis緩存

    Spring Cache手動(dòng)清理Redis緩存

    這篇文章主要介紹了Spring Cache手動(dòng)清理Redis緩存,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-10-10
  • Java中有什么工具可以進(jìn)行代碼反編譯詳解

    Java中有什么工具可以進(jìn)行代碼反編譯詳解

    這篇文章主要介紹了Java中有什么工具可以進(jìn)行代碼反編譯的相關(guān)資,料,包括JD-GUI、CFR、Procyon、Fernflower、Javap、BytecodeViewer、Krakatau和JAD,每種工具都有其特點(diǎn)和適用場(chǎng)景,需要的朋友可以參考下
    2025-03-03
  • java 中Executor, ExecutorService 和 Executors 間的不同

    java 中Executor, ExecutorService 和 Executors 間的不同

    這篇文章主要介紹了java 中Executor, ExecutorService 和 Executors 間的不同的相關(guān)資料,需要的朋友可以參考下
    2017-06-06

最新評(píng)論

英吉沙县| 运城市| 武汉市| 井陉县| 齐齐哈尔市| 淮北市| 普陀区| 西乌珠穆沁旗| 镇坪县| 大同市| 长治市| 新昌县| 巴林左旗| 大兴区| 朝阳县| 富川| 新晃| 古交市| 涿州市| 得荣县| 崇仁县| 布尔津县| 金沙县| 汽车| 沙田区| 和静县| 泸州市| 乌海市| 岳阳县| 绥棱县| 吉隆县| 富锦市| 桃江县| 房产| 渑池县| 泾阳县| 太湖县| 淅川县| 勐海县| 宁津县| 商洛市|