| | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | | import java.util.TimeZone; |
| | | |
| | | import org.jeecg.common.constant.SymbolConstant; |
| | | import org.springframework.util.StringUtils; |
| | |
| | | return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | } |
| | | }; |
| | | public static ThreadLocal<SimpleDateFormat> hoursAndMinutes = new ThreadLocal<SimpleDateFormat>() { |
| | | @Override |
| | | protected SimpleDateFormat initialValue() { |
| | | return new SimpleDateFormat("HH:mm:ss"); |
| | | } |
| | | }; |
| | | public static ThreadLocal<SimpleDateFormat> monthFormat = new ThreadLocal<SimpleDateFormat>() { |
| | | @Override |
| | | protected SimpleDateFormat initialValue() { |
| | | return new SimpleDateFormat("yyyy-MM"); |
| | | } |
| | | }; |
| | | |
| | | public static ThreadLocal<SimpleDateFormat> yearFormat = new ThreadLocal<SimpleDateFormat>() { |
| | | @Override |
| | | protected SimpleDateFormat initialValue() { |
| | | return new SimpleDateFormat("yyyy"); |
| | | } |
| | | }; |
| | | /** |
| | | * 以毫秒表示的时间 |
| | | */ |
| | |
| | | calendar.setTime(getDate()); |
| | | return calendar.get(Calendar.YEAR); |
| | | } |
| | | |
| | | public static String getDayStr(Date date) { |
| | | Calendar calendar = getCalendar(); |
| | | calendar.setTime(date);// 把当前时间赋给日历 |
| | | int day = calendar.get(Calendar.DATE);// 获取日 |
| | | String dayStr = day < 10 ? "0" + day : day + ""; |
| | | return dayStr; |
| | | } |
| | | /** |
| | | * 将字符串转成时间 |
| | | * @param str |
| | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定时间之后的几天 qsw |
| | | */ |
| | | public static Date getDayAfter(Date data,int number) { |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(data); |
| | | c.add(Calendar.DAY_OF_MONTH, number); |
| | | Date afterTime = c.getTime(); |
| | | // SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | // String resultDate = f.format(afterTime); |
| | | return afterTime; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定时间之后的几分钟 qsw |
| | | */ |
| | | public static Date getMinAfter(Date data,int number) { |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(data); |
| | | c.add(Calendar.MINUTE, number); |
| | | Date afterTime = c.getTime(); |
| | | return afterTime; |
| | | } |
| | | |
| | | /** |
| | | * 获取指定时间之后的几小时 qsw |
| | | */ |
| | | public static Date getHourAfter(Date data,int number) { |
| | | Calendar c = Calendar.getInstance(); |
| | | c.setTime(data); |
| | | c.add(Calendar.HOUR_OF_DAY, number); |
| | | Date afterTime = c.getTime(); |
| | | return afterTime; |
| | | } |
| | | |
| | | public static String getCurrentDateStr() { |
| | | Date date = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); |
| | | dateFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));// 设置北京时区 |
| | | return dateFormat.format(date); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | } |