//去掉小数点后多余的0
public static String subZeroAndDot(String s){
if(s.indexOf(".") > 0){
s = s.replaceAll(“0+?
"
,
"
"
)
;
/
/
去
掉
多
余
的
0
s
=
s
.
r
e
p
l
a
c
e
A
l
l
(
"
[
.
]
", "");//去掉多余的0 s = s.replaceAll("[.]
","");//去掉多余的0s=s.replaceAll("[.]”, “”);//如最后一位是.则去掉
}
return s;
}
//去除字符串空格
public void delSpacebar(){
String a= "fdi34 09df jk “;
//a= a.replace(” ", “”); //replace转换参数是字符串;replaceAll转换参数是正则表达式
a = a.trim(); //删除字符串头尾的空格
System.out.println(a);
}
//把手机号的中间四位转为****
public static String switchPhone(String phone){
if (phone.length() == 11) {
if(Pattern.compile("[0-9]").matcher(phone).matches()) {
phone = phone.substring(0, 3) + phone.substring(3).replaceAll("^\d{4}", "***");
}else{
phone = “存在非数字”;
}
}else {
phone = “长度有误”;
}
return phone;
}
//首字母大写
public String upperCase(String str) {
return str.substring(0, 1).toUpperCase() + str.substring(1);
}
@Test
//时间处理
public void date(){
try {
Long timeStamp = System.currentTimeMillis(); //获取当前时间戳
System.out.println(timeStamp);
Date nowDate = new Date(); //当前时间
System.out.println(nowDate);
//DateFormat df = new SimpleDateFormat(“yyyy-MM-dd E a HH:mm:ss”);
SimpleDateFormat sdf=new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); //SimpleDateFormat是DateFormat子类,通常使用SimpleDateFormat
String dateStr = sdf.format(nowDate); //时间格式转换为字符串格式
System.out.println(dateStr);
Date date = sdf.parse(dateStr); //字符串格式转为时间格式
System.out.println(date);
} catch (ParseException e) {
e.printStackTrace();
}
}