zoukankan      html  css  js  c++  java
  • MyTimeUtil--个人最常用时间管理方法

    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    /**
     * @Author chenrd
     * @Date 2021-6-7 上午11:02:03
     * @Version 1.0 业务说明:本类默认时间格式采用yyyy-MM-dd
     *   
     */
    public class MyTimeUtil {
        public static String fmtTime="yyyy-MM-dd";
        public static String fmtTimeStamp="yyyy-MM-dd HH:mm:ss";
        public static SimpleDateFormat sdf = new SimpleDateFormat(fmtTime);
        public static SimpleDateFormat sdfTime = new SimpleDateFormat(fmtTimeStamp);
        public static void main(String[] args) {
    
        }
    
        /**
         * 字符串的日期加上一天,在返回字符串
         */
        public static String addOneDay(String countdate) throws Exception {
            Calendar c = Calendar.getInstance();
            c.setTime(sdf.parse(countdate));
            c.add(Calendar.DATE, 1);
            String rtn = sdf.format(c.getTime());
            return rtn;
        }
    
        /**
         * 字符串的日期加上一天,在返回字符串
         */
        public static String subOneDay(String countdate) throws Exception {
            
            Calendar c = Calendar.getInstance();
            c.setTime(sdf.parse(countdate));
            c.add(Calendar.DATE, -1);
            String rtn = sdf.format(c.getTime());
            return rtn;
        }
        
        /**
         * @param countdate
         * @param num (负数就是减,正数就是加)
         * @return 字符串的日期加上自定义天,在返回字符串
         * @throws Exception 
         * String
         * 
         */
        public static String addSomeDay(String countdate,int num) throws Exception {
            Calendar c = Calendar.getInstance();
            c.setTime(sdf.parse(countdate));
            c.add(Calendar.DATE, num);
            String rtn = sdf.format(c.getTime());
            return rtn;
        }
    
        /**
         * @param countdate
         * @return 返回年第一天,如2021-01-01
         * @throws Exception 
         * String
         * 
         */
        public static String getYearfirstDay(String countdate) throws Exception {
            String rtn =  countdate.substring(0, countdate.length() - 5) + "01-01";
            return rtn;
        }
        /**
         * @param countdate
         * @return 返回年最后一天,如2021-12-12
         * @throws Exception 
         * String
         * 
         */
        public static String getYearLastDay(String countdate) throws Exception {
            String rtn =  countdate.substring(0, countdate.length() - 5) + "12-12";
            return rtn;
        }
        
        /**
         * 获取当月第一天(传参)
         * 
         * @return
         * @throws ParseException
         */
        public static Date getMonthFirstDay(String rq) throws ParseException {
            Calendar ca = Calendar.getInstance();
            ca.setTime(new SimpleDateFormat(fmtTime).parse(rq));
            ca.set(Calendar.DAY_OF_MONTH, ca.getActualMinimum(Calendar.DAY_OF_MONTH));
            return ca.getTime();
        }
    
        /**
         * 获取当月最后一天(传参)
         * 
         * @return
         * @throws ParseException
         */
        public static Date getMonthLastDay(String rq) throws ParseException {
            Calendar ca = Calendar.getInstance();
            ca.setTime(new SimpleDateFormat(fmtTime).parse(rq));
            ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
            return ca.getTime();
        }
    
        
        /**
         * 获取当前星期几
         *    调用方法, week(c.get(Calendar.DAY_OF_WEEK)) 
         * @return
         */
        public String week(int i) {
            String[] week = new String[] { "星期日","星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
            return week[i-1];
        }
    }
  • 相关阅读:
    Web APIs
    变量替换
    用shell脚本实现文件、代码同步上线
    20.31 expect脚本同步文件 20.32 expect脚本指定host和要同步的文件 20.33 构建文件分发系统 20.34 批量远程执行命令
    20.27 分发系统介绍 20.28 expect脚本远程登录 20.29 expect脚本远程执行命令 20.30 expect脚本传递参数
    20.23/20.24/20.25 告警系统邮件引擎 20.26 运行告警系统
    20.16/20.17 shell中的函数 20.18 shell中的数组 20.19 告警系统需求分析
    20.5 shell脚本中的逻辑判断 20.6 文件目录属性判断 20.7 if特殊用法 20.8/20.9 case判断
    16进制数据拆分
    16进制数据拼接成一个
  • 原文地址:https://www.cnblogs.com/rdchen/p/14858077.html
Copyright © 2011-2022 走看看