zoukankan      html  css  js  c++  java
  • 获取当前日期、当月月初日期、月末日期

    public static void main(String[] args) {
            // 获取当前年份、月份、日期
            Calendar cale = Calendar.getInstance();
            int year = cale.get(Calendar.YEAR);
            int month = cale.get(Calendar.MONTH) + 1;
            int day = cale.get(Calendar.DATE);
            int hour = cale.get(Calendar.HOUR_OF_DAY);
            int minute = cale.get(Calendar.MINUTE);
            int second = cale.get(Calendar.SECOND);
            int dow = cale.get(Calendar.DAY_OF_WEEK);
            int dom = cale.get(Calendar.DAY_OF_MONTH);
            int doy = cale.get(Calendar.DAY_OF_YEAR);
    
            System.out.println("Current Date: " + cale.getTime());
            System.out.println("Year: " + year);
            System.out.println("Month: " + month);
            System.out.println("Day: " + day);
            System.out.println("Hour: " + hour);
            System.out.println("Minute: " + minute);
            System.out.println("Second: " + second);
            System.out.println("Day of Week: " + dow);
            System.out.println("Day of Month: " + dom);
            System.out.println("Day of Year: " + doy);
    
            // 获取当月第一天和最后一天
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            String firstday, lastday;
            // 获取前月的第一天
            cale = Calendar.getInstance();
            cale.add(Calendar.MONTH, 0);
            cale.set(Calendar.DAY_OF_MONTH, 1);
            firstday = format.format(cale.getTime());
            // 获取前月的最后一天
            cale = Calendar.getInstance();
            cale.add(Calendar.MONTH, 1);
            cale.set(Calendar.DAY_OF_MONTH, 0);
            lastday = format.format(cale.getTime());
            System.out.println("本月第一天和最后一天分别是 : " + firstday + " and " + lastday);
        }
  • 相关阅读:
    深入浅出SQL教程之Group by和Having
    AFNetworking3.0 Https P12证书
    C#访问注册表
    One reason for not able to show chinese correctly in installation
    Debugging DLL loading issues with GFLAGS
    RegistryFree COM Registration
    RegistrationFree COM Interop
    net use
    MS UI Automation原来如此
    取景器的视野率和放大倍率
  • 原文地址:https://www.cnblogs.com/jiefu/p/10111861.html
Copyright © 2011-2022 走看看