public static void main(String[]args) { String str="2010-12-25 12:23:40"; System.out.println(format1(str)); System.out.println(format2(str)); } public static String format1(String str){ return str.substring(0,10).replace("-",""); } public static String format2(String str){ java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); java.util.Date temp = df.parse(str, new java.text.ParsePosition(0)); df=new java.text.SimpleDateFormat("yyyyMMdd"); return df.format(temp); }
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd HHmmss"); Date date = sdf.parse("2010-12-25 12:23:40"); sdf = new SimpleDateFormat("yyyyMMdd"); System.out.println(sdf.format(date));String str="2010-12-25 12:23:40"; System.out.println(str.split(" ")[0].replaceAll("-",""));没有ide你自己试试吧。
public static void main(String[]args)
{
String str="2010-12-25 12:23:40";
System.out.println(format1(str));
System.out.println(format2(str));
}
public static String format1(String str){
return str.substring(0,10).replace("-","");
}
public static String format2(String str){
java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
java.util.Date temp = df.parse(str, new java.text.ParsePosition(0));
df=new java.text.SimpleDateFormat("yyyyMMdd");
return df.format(temp);
}
Date date = sdf.parse("2010-12-25 12:23:40");
sdf = new SimpleDateFormat("yyyyMMdd");
System.out.println(sdf.format(date));String str="2010-12-25 12:23:40";
System.out.println(str.split(" ")[0].replaceAll("-",""));没有ide你自己试试吧。