Tools continuously updated

/ ** 
* develop common tools
* /
public class BaseCompareUtil {
/ **
* Class time
* getDayOfWeek --------- get on the first day of January of the week
* getDayOfMonth ------- - get the maximum number of days in January
* stampToDateTime ---------- timestamp converted to time
* stringToDateTime --------- String to timestamp
* getTodayDate ------ ---- get today date MM-dd-yyyy
* getAfterDayDate ---------- get a few days later date MM-dd-yyyy
* getBeforeDayDate ---------- get a few days ago date yyyy dd--MM
* -------------- belongCalendar determines whether the time period
* caculateTotalTime number of days between two dates -----------
* /
/ / Get the first day of the week of January
public static int the getDayOfWeek (Y int, int m, int day) {
Calendar Calendar Calendar.getInstance = ();
calendar.set(y, m - 1, day);
return calendar.get(Calendar.DAY_OF_WEEK);
}

//获取一月最大天数
public static int getDayOfMonth(int y, int m) {
Calendar cal = Calendar.getInstance();
cal.set(y, m - 1, 1);
return cal.getActualMaximum(Calendar.DATE);
}

/**
* 将时间戳转换为时间
*/
public static String stampToDateTime(long s) {
if (s == 0) {
return "";
}
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Date date = new Date(s);
res = simpleDateFormat.format(date);
return res;
}

/**
* 将String转换为时间
*/
public static String stringToDateTime(String s) {
if (TextUtils.isEmpty(s)) {
return null;
}
try {
String res;
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = simpleDateFormat.parse(s);
SimpleDateFormat simpleDateFormatTo = new SimpleDateFormat("yyyy-MM-dd");
res = simpleDateFormatTo.format(date);
return res;
} catch (ParseException e) {
return "";
}
}

/**
* 获取今日日期yyyy-MM-dd
*/
public static String getTodayDate() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
Calendar calendar = Calendar.getInstance();
return simpleDateFormat.format(calendar.getTime());
}

/**
* 获取几日后日期yyyy-MM-dd
*/
public static String getAfterDayDate(int day) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + day);
return simpleDateFormat.format(calendar.getTime());
}

/ **
* Get a few days ago the MM-dd-date YYYY
* /
public static String getBeforeDayDate (int Day) {
the SimpleDateFormat SimpleDateFormat the SimpleDateFormat new new = ( "the MM-dd-YYYY", Locale.getDefault ());
Calendar Calendar Calendar = .getInstance ();
calendar.set (Calendar.DATE, Calendar.get (Calendar.DATE) - Day);
return simpleDateFormat.format (calendar.getTime ());
}


/ **
* * determines whether the time period
* * 
* * @param nowtime
* * @param beginTime
* * @param endTime
* * @return not performed. 1 2 3 have been
*     
* /
public static String belongCalendar(Date nowTime, Date beginTime, Date endTime) {
String type;
if (nowTime.getTime() < beginTime.getTime()) {
type = "1";
} else if (nowTime.getTime() > endTime.getTime()) {
type = "3";
} else {
type = "2";
}
return type;
}

/**
* 计算 两个日期之间天数
*
* @param startTime
* @param endTime
* @return
* @throws ParseException
*/
public static int caculateTotalTime(String startTime, String endTime) throws ParseException {
Formatter new new = the SimpleDateFormat the SimpleDateFormat ( "the MM-dd-YYYY");
a Date date1 = null;
a Date DATE = formatter.parse (the startTime);
Long date.getTime TS = ();
date1 = formatter.parse (endTime);
Long tsl date1.getTime = ();
Long tsl = TS2 - TS;
int totalTime, = 0;
totalTime, = (int) (TS2 / (24 * 3600 * 1000) +. 1);
return totalTime,;
}
/ ***
* based functional effect
*
* isFastClick ------------ quick click
* newInstance ------------ click wrap effect
*
*
*
*
*
*
* /
/ **
* two clicks click on the spacing between the buttons of not less than 1000 ms
* /
Private Final static int MIN_CLICK_DELAY_TIME = 1000;
Private Long static lastClickTime = -1;

/ **
* whether a quick click
*
* @return quick click
* /
public static Boolean isFastClick () {
Boolean In Flag;
Long curClickTime = System.currentTimeMillis ();
IF (curClickTime - lastClickTime> MIN_CLICK_DELAY_TIME) {
In Flag = to false;
} the else {
In Flag = to true;
}
lastClickTime = curClickTime;
return In Flag;
}

/ **
* click wrapped effects
* /
private View hideView, clickView, down;//需要展开隐藏的布局,开关控件

public static BaseCompareUtil newInstance(Context context, View hideView, View clickView, ImageView down) {
clickView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (View.VISIBLE == hideView.getVisibility()) {
hideView.setVisibility(View.GONE);
down.setImageResource(R.drawable.svg_bottom_c126);
} else {
hideView.setVisibility(View.VISIBLE);
down.setImageResource(R.drawable.svg_top_c126);
}
}
});
return new BaseCompareUtil(context, hideView, clickView, down);
}

private BaseCompareUtil(Context context, View hideView, View clickView, View down) {
this.hideView = hideView;
this.down = down;
this.clickView = clickView;
}
}

Guess you like

Origin www.cnblogs.com/sunjian43792901/p/11368502.html