• commons lang3 日期处理


    DateUtils常用方法

    package sms;
    
    import com.alibaba.fastjson.JSONObject;
    import org.apache.commons.lang3.time.DateFormatUtils;
    import org.apache.commons.lang3.time.DateUtils;
    
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    
    public class Date_02 {
        public static void main(String[] args) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            Date now = new Date();
            Calendar cal = Calendar.getInstance();
            cal.setFirstDayOfWeek(Calendar.MONDAY);
            //获取本星期第1天
            cal.setTime(now);
            int wich = cal.get(Calendar.DAY_OF_WEEK);
            System.out.println(wich);
            cal.add(Calendar.WEEK_OF_YEAR, -1);
            Date time = cal.getTime();
    
            System.out.println(sdf.format(now));
            /*
            2020-03-01 14:11:15.420
            2020-03-01 00:00:00.000
            2020-03-01 00:00:00.000
            2020-03-01 14:00:00.000
            2020-03-01 14:11:00.000
             */
            System.out.println(sdf.format(DateUtils.truncate(now, Calendar.MONTH)));
            System.out.println(sdf.format(DateUtils.truncate(now, Calendar.DAY_OF_MONTH)));
            System.out.println(sdf.format(DateUtils.truncate(now, Calendar.HOUR)));
            System.out.println(sdf.format(DateUtils.truncate(now, Calendar.MINUTE)));
    
            //格式化日期
            String str = DateFormatUtils.format(now, "yyyyMMdd");
            System.out.println(str);
            System.out.println(JSONObject.toJSONString(time));
        }
    }
    
  • 相关阅读:
    Matlab quad
    卷积神经网络(CNN)代码实现(MNIST)解析
    Redis具体解释
    Nginx Https 配置
    Nginx 常用配置
    Nginx gzip压缩配置
    Nginx 静态资源配置
    Idea给类和方法增加注释模板
    MySql定时备份数据库
    Nginx 日志切割
  • 原文地址:https://www.cnblogs.com/mozq/p/12389631.html
Copyright © 2020-2023  润新知