package tools;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateTools {
static SimpleDateFormat smp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
public static Date strToDateTime(String s) {
if (s==null) return null ;
try {
return smp.parse(s);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String dateToStr(Date s) {
if (s==null) return null ;
return smp.format(s);
}
public static int getYear(Date dt) {
if (dt==null) {
return -1;
}
String s = smp.format(dt);
return Integer.valueOf(s.substring(0,4)) ;
}
public static int getMonth(Date dt) {
if (dt==null) {
return -1;
}
String s = smp.format(dt);
return Integer.valueOf(s.substring(5,7)) ;
}
public static int getDays(Date dt) {
if (dt==null) {
return -1;
}
String s = smp.format(dt);
return Integer.valueOf(s.substring(8,10)) ;
}
public static void main(String s[]) {
System.out.println(DateTools.getYear(new Date()));
System.out.println(DateTools.getMonth(new Date()));
System.out.println(DateTools.getDays(new Date()));
}
}
最近下载更多
最近浏览更多
dddding yang LV6
9月15日
木子520 LV12
5月23日
vitos5n LV10
2024年12月9日
dearxo2014 LV1
2024年11月9日
PSSDZH LV3
2024年6月14日
welcome丶 LV9
2024年4月26日
香菇肉饼汤 LV8
2024年4月21日
小王wang LV10
2024年2月29日
houxianzheng
2024年2月19日
暂无贡献等级
氟西汀来救你 LV2
2024年1月10日

