80,351
社区成员
发帖
与我相关
我的任务
分享
String s="20080105";
Pattern p = Pattern.compile("(\\d{4})(\\d{2})(\\d{2})");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1)+"-"+m.group(2)+"-"+m.group(3)) ;
}
public class DateTime {
private static SimpleDateFormat hmSdf = new SimpleDateFormat("HH");
private static SimpleDateFormat mdSdf = new SimpleDateFormat(":mm");
private static SimpleDateFormat ymdSdf = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat yearSdf = new SimpleDateFormat("yyyy");
private static SimpleDateFormat mmsdf = new SimpleDateFormat("MM");
private static SimpleDateFormat ddsdf = new SimpleDateFormat("dd");
public static int getTimestamp() {
return (int)(System.currentTimeMillis()/1000);
}
public static String getDateString(){
return getDateTimeStringFormat("yyyy-MM-dd");
}
public static String getDateTimeString(){
return getDateTimeStringFormat("yyyy-MM-dd kk:mm:ss");
}
public static String getDateTimeStringFormat(String dateFormat){
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat);
Date date = new Date();
return simpleDateFormat.format(date);
}
}