12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- package com.yihu.jw.util;/**
- * Created by nature of king on 2018/5/11.
- */
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.GregorianCalendar;
- /**
- * @author wangzhinan
- * @create 2018-05-11 14:02
- * @desc date component
- **/
- public class DateUtils {
- private final static SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- //获取当天的开始时间
- public static String getDayBegin() {
- Calendar cal = new GregorianCalendar();
- cal.set(Calendar.HOUR_OF_DAY, 0);
- cal.set(Calendar.MINUTE, 0);
- cal.set(Calendar.SECOND, 0);
- cal.set(Calendar.MILLISECOND, 0);
- return sdf.format(cal.getTime());
- }
- //获取当天的结束时间
- public static String getDayEnd() {
- Calendar cal = new GregorianCalendar();
- cal.set(Calendar.HOUR_OF_DAY, 23);
- cal.set(Calendar.MINUTE, 59);
- cal.set(Calendar.SECOND, 59);
- return sdf.format(cal.getTime());
- }
- // 获得当前月--开始日期
- public static String getMinMonthDate(String date) {
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Calendar calendar = Calendar.getInstance();
- try {
- calendar.setTime(dateFormat.parse(date));
- calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
- return dateFormat.format(calendar.getTime());
- } catch (java.text.ParseException e) {
- e.printStackTrace();
- }
- return null;
- }
- // 获得当前月--结束日期
- public static String getMaxMonthDate(String date){
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
- Calendar calendar = Calendar.getInstance();
- try {
- calendar.setTime(dateFormat.parse(date));
- calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
- return dateFormat.format(calendar.getTime());
- } catch (java.text.ParseException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * 获取两天时间相差的
- *
- * @param endDate
- * @param nowDate
- * @return
- */
- public static String getDatePoor(Date endDate, Date nowDate) {
- long nd = 1000 * 24 * 60 * 60;
- long nh = 1000 * 60 * 60;
- long nm = 1000 * 60;
- long diff = endDate.getTime() - nowDate.getTime();
- long day = diff / nd;//计算相差多少天
- long hour = diff % nd / nh;//计算相差多少小时
- long min = diff % nd % nh / nm;//计算相差多少分钟
- return day+"h "+hour+" h"+min+" m";
- }
- }
|