码迷,mamicode.com
首页 > 编程语言 > 详细

java代码获取当前时间是本周、本月、本年的第几天

时间:2020-03-19 21:26:29      阅读:51      评论:0      收藏:0      [点我收藏+]

标签:instance   static   day   print   div   nbsp   int   获取   integer   

  public static void getWeekMonthYear(){
        Map<String, Integer> mapInt = new LinkedHashMap<String, Integer>();
        Calendar calendar = Calendar.getInstance();
        Date today = new Date();
        calendar.setTime(today);// 此处可换为具体某一时间
        int weekDay = calendar.get(Calendar.DAY_OF_WEEK);
        int monthDay = calendar.get(Calendar.DAY_OF_MONTH);
        int yearDay = calendar.get(Calendar.DAY_OF_YEAR);
        if (weekDay == 1) {
            weekDay = 7;
        } else {
            weekDay = weekDay - 1;
        }
        mapInt.put("周", weekDay);
        mapInt.put("月", monthDay);
        mapInt.put("年", yearDay);
        for (Map.Entry<String, Integer> entry : mapInt.entrySet()) {
            System.out.println("今天是本" + entry.getKey() + "的第" + entry.getValue() + "天");
        }
    }

 

java代码获取当前时间是本周、本月、本年的第几天

标签:instance   static   day   print   div   nbsp   int   获取   integer   

原文地址:https://www.cnblogs.com/52KT9/p/12527001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!