您的位置:首页 > 其它

有用的函数

2015-05-15 10:40 120 查看
1、判断对象是否为空

public static boolean isEmpty(Object o){
if(o==null)
return true;
if(o instanceof String){
String str=(String) o;
if("".equals(str))
return true;
}
return false;
}


 

2、得到当前时间

public static Timestamp getCurrentTimestamp() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(new Date());
return Timestamp.valueOf(date);
}


 

3、首字母大写

public static String capitalizeStr(String str){
String result=Character.toUpperCase(str.charAt(0))+str.substring(1, str.length());
return result;
}


 

4、时间格式化

public static String getYYYYMMDDHHmmss(Date date){
if(date==null)
return "";
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String str = sdf.format(date);
return str;
}


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: