importer java.text.ParseException ;
importer java.text.SimpleDateFormat ;
importer java.util.Date ;
classe publique DateIO {
public static void main (String[] arguments) {
Date date= new DateIO().strToDate("2013-04-01");
String strdate=new DateIO().dateToStr(date);
String srrdate=new DateIO().timestampToStr(System.currentTimeMillis());
Horodatage ts=new DateIO().strToTimestamp(new Date());
}
//String 转换为 Date
Date publique strToDate(String strdate){
Format DateFormat = new SimpleDateFormat("aaaa-MM-jj");
Date date = nulle ;
essayer {
date = format.parse(strdate);
} catch (ParseException e) {
e.printStackTrace();
}
System.out.println("date:"+date);
date de retour ;
}
//Date 转换为 Chaîne
chaîne publique dateToStr(Date date){
//年月日****-**-**
Format DateFormat = new SimpleDateFormat("aaaa-MM-jj");
Chaîne str = format.format(date);
System.out.println("str:"+str);
//年月日**-*-*
format = DateFormat.getDateInstance(DateFormat.SHORT);
str = format.format(date);
System.out.println(str);
//年月日****-*-*
format = DateFormat.getDateInstance(DateFormat.MEDIUM);
str = format.format(date);
System.out.println(str);
//****年*月*日星期*
format = DateFormat.getDateInstance(DateFormat.FULL);
str = format.format(date);
System.out.println(str);
return str;
}
//Timestamp转换为String
public String timestampToStr (horodatage long) {
SimpleDateFormat df = new SimpleDateFormat("aaaa-MM-jj HH:mm:ss");//定义格式,不显示毫秒
String str = df.format(horodatage);
System.out.println(str);
return str;
}
//Date转换为Horodatage
public Timestamp strToTimestamp(Date date){
SimpleDateFormat df = new SimpleDateFormat("aaaa-MM-jj HH:mm:ss");
Heure de chaîne = df.format(date);
Horodatage ts = Timestamp.valueOf(time);
System.out.println(ts);
retourner ts ;
}
}