//将字符串日期转换成日期类型
public static Timestamp getTimestamp(String tDate){
if(tDate!=null){
Timestamp ts = Timestamp.valueOf(tDate+" 00:00:000000000");
return ts;
}
return null;
}
//得到某年某月有多少天
public static int getLastDayOfMonth(int year,int mon){
int LastDayOfMonth = 0;
try{
Calendar aa = Calendar.getInstance();
aa.set(year, mon-1, 1);
aa.roll(Calendar.DATE, -1);
LastDayOfMonth = aa.get(Calendar.DATE);
}catch(Exception e){
e.printStackTrace();
}
return LastDayOfMonth;
}
//去掉字符串首尾的空格
public static String getStringByRegex(String str){
String reg = "(^\\s*)|(\\s*$)"; //匹配首尾空格正则模式
if(str != null){
str = str.replaceAll(reg, "");
}
return str;
}
//对字符串数组进行排序
public static String[] StrArraySort(String[] arr){
Comparator cmp = (RuleBasedCollator)java.text.Collator.getInstance(java.util.Locale.CHINA);
java.util.Arrays.sort(arr, cmp);
return arr;
}
//根据要保留的小数位数dit,将rander四舍五入
public static double getNumberRound(double rander, int dit){
double iRound;
BigDecimal bd = new BigDecimal(rander);
iRound = bd.setScale(dit, BigDecimal.ROUND_HALF_DOWN).doubleValue();
return iRound;
}
//获取yyyy-MM-dd是星期几
public static int getWeekdayOfDateTime(String datetime){
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try {
c.setTime(df.parse(datetime));
} catch (Exception e) {
e.printStackTrace();
}
int weekday = c.get(Calendar.DAY_OF_WEEK)-1;
return weekday;
}
//24小时制的分钟自减器(将HH修改为hh则是12小时制)
public static String getMinByNowDate(String dateTime,int i){
String dt = "";
if(dateTime!=null){
Calendar now = Calendar.getInstance();
Timestamp ts = Timestamp.valueOf(dateTime);
now.setTime(ts);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
now.add(Calendar.MINUTE,-(i));
dt = formatter.format(now.getTime());
}
return dt;
}