Java中获得查询日期的上月末的日期

Posted gamedev˚

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java中获得查询日期的上月末的日期相关的知识,希望对你有一定的参考价值。

Java中获得查询日期的上月末的日期,通过calendar类来进行日期格式的转换和调用。
具体代码如下,注释即为代码解析

    @Bizlet("获得查询日期的上月末的日期")
        public String getLastMonthDate(String DateStr) throws ParseException
            SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd");       // 指定日期输出格式
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dataFormat.parse(DateStr));                            // 设置当前日历实例的时间
            calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)-1);           // 设置日历实例的月取值
            calendar.set(Calendar.DATE, calendar.getMaximum(Calendar.DATE));        // 设置日历实例的日取值
            Date date = calendar.getTime();                                         // 得到日历实例表示的当前时间
            return dataFormat.format(date).toString();                              // 以指定格式输出上月末的日期
        

转载请注明出处:http://blog.csdn.net/coder__cs/article/details/79176538
本文出自【elon33的博客

以上是关于Java中获得查询日期的上月末的日期的主要内容,如果未能解决你的问题,请参考以下文章