激情久久久_欧美视频区_成人av免费_不卡视频一二三区_欧美精品在欧美一区二区少妇_欧美一区二区三区的

服務器之家:專注于服務器技術及軟件下載分享
分類導航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

香港云服务器
服務器之家 - 編程語言 - JAVA教程 - 使用java的Calendar對象獲得當前日期

使用java的Calendar對象獲得當前日期

2019-12-25 13:26hebedich JAVA教程

本文給大家分享的是使用使用java的Calendar對象獲得當前日期的上幾個度開始、結束時間,主要思路是先獲得當前季度的開始和結束日期,在當前日期的基礎上往前推3個月即上個季度的開始和結束日期,十分的實用,小伙伴們可以參

思路:

先獲得當前季度的開始和結束日期,在當前日期的基礎上往前推3個月即上個季度的開始和結束日期

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
   * @param flag true:開始日期;false:結束日期
   * @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:結束日期
      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);// 設置日期
      calendar.add(Calendar.MONTH, -3);
      resultDate = longSdf.format(calendar.getTime());
       
    } catch (Exception e) {
      ;
    }
    return resultDate;
  }

延伸 · 閱讀

精彩推薦
284
主站蜘蛛池模板: 欧美国产日韩在线观看成人 | 亚洲国产网站 | 99久久精品日本一区二区免费 | 亚洲精品自在在线观看 | 天堂亚洲一区 | 免费观看一级黄色片 | 午夜啪视频 | 日本免费aaa观看 | 一分钟免费观看完整版电影 | 精品国产91一区二区三区 | 91情侣在线偷精品国产 | 国产精品一区二区日韩 | 一级毛片在线看 | 91精品久久久久久久久网影视 | 蜜桃视频在线播放 | 精品视频一区二区三区四区 | 视频一区二区不卡 | 99精品国产小情侣高潮露脸在线 | 日日草夜夜操 | 国产羞羞视频在线观看免费应用 | 看免费的毛片 | 国产一级αv片免费观看 | 国内xxxx乱子另类 | 成人精品视频网站 | 九九热在线视频观看这里只有精品 | 午夜视频色 | 免费a级片在线观看 | 国产成人自拍av | 双性精h调教灌尿打屁股的文案 | 中文字幕在线观看视频一区 | 久草热久| 国产一级免费不卡 | 日韩毛片在线看 | 亚洲一区二区三区四区精品 | av免费大全 | 久久精品一二三区白丝高潮 | 视频一区免费观看 | 日本在线观看视频网站 | 免费看搡女人无遮挡的视频 | av电影在线网站 | 中文字幕激情 |