utils.java
来自「图书馆管理的源代码文件」· Java 代码 · 共 101 行
JAVA
101 行
package com.nitpro.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Utils {
public static boolean isDateFmt(String str, String fmt){
boolean r = false;
try {
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
Date d = sdf.parse(str);
r = true;
} catch (Exception e) {
//e.printStackTrace();
}finally{
return r;
}
}
public static boolean isDoubleFmt(String str){
boolean r = false;
try {
double d = Double.parseDouble(str);
r = true;
} catch (Exception e) {
//e.printStackTrace();
}finally{
return r;
}
}
public static boolean isIntegerFmt(String str){
boolean r = false;
try {
int d = Integer.parseInt(str);
r = true;
} catch (Exception e) {
//e.printStackTrace();
}finally{
return r;
}
}
public static Date strToDate(String str, String fmt){
Date d = null;
if(!isDateFmt(str, fmt)){
return d;
}else{
try {
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
d = sdf.parse(str);
} catch (Exception e) {
e.printStackTrace();
}
}
return d;
}
public static String dateToStr(Date date, String fmt){
String str = "";
if(date == null){
return str;
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
str = sdf.format(date);
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
public static Double strToDouble(String str){
Double d = null;
if(!isDoubleFmt(str)){
return d;
}else{
try {
d = Double.parseDouble(str);
} catch (Exception e) {
e.printStackTrace();
}
}
return d;
}
public static Integer strToInteger(String str){
Integer d = null;
if(!isIntegerFmt(str)){
return d;
}else{
try {
d = Integer.parseInt(str);
} catch (Exception e) {
e.printStackTrace();
}
}
return d;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?