📄 utils.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -