Crunchy
2025-06-14 b2f31607cbe26d721cd7514b619162b3e355b1aa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.wms_admin.utils;
 
import org.springframework.stereotype.Component;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Random;
 
@Component
public class MyUtils {
 
    public static String MyDateFormat(){
        //获取日期
        //导 import java.util.Date; 下的包
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return sdf.format(date);
    }
 
    /**
     *2018-12-27T16:00:00.000Z 转换为Date
     * @param time
     * @return
     * @throws ParseException
     */
    public static Date toDate(String time) throws ParseException {
        String TimeStart = time.replace("Z", " UTC");
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
        return format.parse(TimeStart);    //Fri Dec 28 00:00:00 GMT+08:00 2018
    }
 
    /**
     * 获取随机加密盐
     * @param n 位数
     * @return 返回随机加密盐
     */
    public static String getSalt(int n) {
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890!@$%^&*.?".toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            char c = chars[new Random().nextInt(chars.length)];
            sb.append(c);
        }
        return sb.toString();
    }
 
    /**
     * 时间去0
     * @param timeStr 需要去0的参数
     * @return 返回格式化后的数据
     */
    public static String getTime_0(Date timeStr) {
        //此处字符串的格式可以修改
        SimpleDateFormat formatter = new SimpleDateFormat("M.d");
        return formatter.format(timeStr);
    }
 
    /**
     * 判断给定日期是否是当月的最后一天
     * @param date
     * @return
     */
    public static boolean isLastDayOfMonth(Date date) {
        //1、创建日历类
        Calendar calendar = Calendar.getInstance();
        //2、设置当前传递的时间,不设就是当前系统日期
        calendar.setTime(date);
        //3、data的日期是N,那么N+1【假设当月是30天,30+1=31,如果当月只有30天,那么最终结果为1,也就是下月的1号】
        calendar.set(Calendar.DATE, (calendar.get(Calendar.DATE) + 1));
        //4、判断是否是当月最后一天【1==1那么就表明当天是当月的最后一天返回true】
        if (calendar.get(Calendar.DAY_OF_MONTH) == 1) {
            return true;
        }else{
            return false;
        }
    }
}