标签:
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.gsoft.cos.core.util.Assert;
import com.gsoft.cos.core.util.BeanUtils;
/**
* @author 作者 E-mail:
* @version 创建时间:2015年9月26日 下午7:30:24
* 类说明
*/
public class GgczUtil {
public String getDateString(Date date,String str){
String dateStr=new SimpleDateFormat(str).format(date);
return dateStr;
}
public Date getDate(Date date,String str) throws ParseException{
SimpleDateFormat sdf=new SimpleDateFormat(str);
Date newdate = (Date) sdf.parse(date.toString());
return newdate;
}
public Date getDate(String date,String str) throws ParseException{
SimpleDateFormat sdf=new SimpleDateFormat(str);
Date newdate = (Date) sdf.parse(date);
return newdate;
}
public String getDateToString(String date,String str) throws ParseException{
SimpleDateFormat dateFormat = new SimpleDateFormat(str);
Date dateStr=null;
try {
dateStr = dateFormat.parse(date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return dateFormat.format(dateStr);
}
@SuppressWarnings({"unchecked", "rawtypes"})
public List< Map<String, Object>> listToMap(List<?> list) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException{
List<Map<String, Object>> lm=new ArrayList<Map<String, Object>>();
for (int i = 0; i < list.size(); i++) {
Map parameter = new HashMap<String, Object>();
parameter = BeanUtils.describe(list.get(i));
lm.add(parameter);
}
return lm;
}
public int daysBetween(Date early, Date late) {
java.util.Calendar calst = java.util.Calendar.getInstance();
java.util.Calendar caled = java.util.Calendar.getInstance();
calst.setTime(early);
caled.setTime(late);
//设置时间为0时
calst.set(java.util.Calendar.HOUR_OF_DAY, 0);
calst.set(java.util.Calendar.MINUTE, 0);
calst.set(java.util.Calendar.SECOND, 0);
caled.set(java.util.Calendar.HOUR_OF_DAY, 0);
caled.set(java.util.Calendar.MINUTE, 0);
caled.set(java.util.Calendar.SECOND, 0);
//得到两个日期相差的天数
int days = ((int) (caled.getTime().getTime() / 1000) - (int) (calst
.getTime().getTime() / 1000)) / 3600 / 24;
if(calst.getTime().getTime()<caled.getTime().getTime()){
days=-days;
}
return days;
}
public boolean isInteger(String str) {// 判断整型
return str.matches("^\\d+$$");
}
public boolean isNumber(String str) {// 判断整数或double
if(isInteger(str)||isDouble(str)){
return true;
}
return false;
}
public boolean isDouble(String str) {// 判断小数,与判断整型的区别在与d后面的小数点(红色)
return str.matches("\\d+\\.\\d+$");
}
public boolean isStartPointNubmer(String str) {// 判断小数点开头
return str.matches("\\.\\d+$");
}
public String getDoubleRound(String str){
if(Assert.isNotEmpty(str)){
return String.format("%.2f", Double.parseDouble(str));
}
return String.format("%.2f", Double.parseDouble("0.00"));
}
/**
* 根据数组符号获得符号间隔字符串
* @param args
* @param symbol
* @return
*/
public String getStringToSymbol(String[] args,String symbol){
String newSymbol=",";
if(Assert.isNotEmpty(symbol)){
newSymbol=symbol;
}
if(Assert.isNotEmpty(args)){
String str="";
for (String string : args) {
str+=string+newSymbol;
}
return str.substring(0,str.length()-1);
}
return "";
}
/**
* 根据数组符号获得符号间隔字符串
* @param args
* @param symbol
* @return
*/
public String getStringToSymbol(Integer[] args,String symbol){
String newSymbol=",";
if(Assert.isNotEmpty(symbol)){
newSymbol=symbol;
}
if(Assert.isNotEmpty(args)){
String str="";
for (Integer string : args) {
str+=string+newSymbol;
}
return str.substring(0,str.length()-1);
}
return "";
}
/**
* @author
* 分割list
* @param list
* @param pageSize
* @return
*/
public static <T> List<List<T>> splitList(List<T> list, int pageSize) {
List<List<T>> listArray = new ArrayList<List<T>>();
ArrayList<T> al = new ArrayList<T>();
for(T x : list){
al.add(x);
if (pageSize == al.size()){
listArray.add(al);
al = new ArrayList<T>();
}
}
if (0 != al.size())
listArray.add(al);
return listArray;
}
}
easyui DataGrid 工具类之 Utils class
标签:
原文地址:http://www.cnblogs.com/ckaifeng/p/5130921.html