zoukankan      html  css  js  c++  java
  • java 日期转星期

    /**
         * 判断当前日期是星期几<br>
         * <br>
         * 
         * @param pTime
         *            修要判断的时间<br>
         * @return dayForWeek 判断结果<br>
         * @Exception 发生异常<br>
         
    */
        public int getDayForWeek(String pTime) throws Exception {
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            Calendar c = Calendar.getInstance();
            c.setTime(format.parse(pTime));
            int dayForWeek = 0;
            if (c.get(Calendar.DAY_OF_WEEK) == 1) {
                dayForWeek = 7;
            } else {
                dayForWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
            }
            return dayForWeek;
        }

        /**
         * 判断当前星期中文名
         
    */
        public String getWeekName(int week) {
            String weekName = "周日";
            switch (week) {
            case 1: {
                weekName = "周一";
                break;
            }
            case 2: {
                weekName = "周二";
                break;
            }
            case 3: {
                weekName = "周三";
                break;
            }
            case 4: {
                weekName = "周四";
                break;
            }
            case 5: {
                weekName = "周五";
                break;
            }
            case 6: {
                weekName = "周六";
                break;
            }
            default: {
                break;
            }
            }
            return weekName;
        }

        public String getWeekNameForDay(int days) {
            SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date dt = new Date();
            dt.setDate(dt.getDate() + days);
            String date = sDateFormat.format(dt);
            int onlineDay = 0;
            try {
                onlineDay = getDayForWeek(date);
                date = getWeekName(onlineDay);
            } catch (Exception e) {

            }
            return date;
        }
  • 相关阅读:
    同步IO,异步IO,阻塞,非阻塞的定义与区别
    RocketMQ之NameServer学习笔记
    RocketMQ消息发送的队列选择与容错策略
    RocketMQ详解
    JVM(HotSpot) 7种垃圾收集器的特点及使用场景
    dubbo SPI设计
    dubbo集群容错之LoadBalance
    dubbo服务引用与集群容错
    dubbo服务暴露过程
    内存溢出排查基本步骤
  • 原文地址:https://www.cnblogs.com/xsmhero/p/2762016.html
Copyright © 2011-2022 走看看