获取当前日期并把年月日放到map中

因为经常有需求要获取当前年月日并且进行一些拼接,所以自己写了个公共方法来实现:

/***
     *
     * @return获取当天年月日
     */
    public static Map<String,Object> getCurrentDate(){
        Calendar now = Calendar.getInstance();
        Map<String,Object> result=new HashMap<>();
        result.put("年",now.get(Calendar.YEAR));
        result.put("月",(now.get(Calendar.MONTH) + 1)<10?"0"+(now.get(Calendar.MONTH) + 1):(now.get(Calendar.MONTH) + 1));
        result.put("日",now.get(Calendar.DAY_OF_MONTH)<10?"0"+now.get(Calendar.DAY_OF_MONTH):now.get(Calendar.DAY_OF_MONTH));
        return result;
    }

这样就可以了!

posted @ 2023-01-09 17:14  浮笙芸芸  阅读(114)  评论(0)    收藏  举报