Package util;
Import java. text. ParseException;
Import java. text. SimpleDateFormat;
Import java. util. Date;
Public class SimpleDateFormatDemo {
/**
* // Write a method to convert a date to a string
*
* @ Param date
* @ Param pattern
* @ Return
*/
Public static String dateCovertStr (Date date, String pattern ){
SimpleDateFormat sdf = new SimpleDateFormat ();
String demo = sdf. format (date );
Return demo;
}
/**
* // Write a method to convert a string to a date.
*
* @ Param parttern
* @ Param source
* @ Return
* @ Throws Exception
*/
Public static Date strCovertDate (String parttern, String source)
Throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat (parttern );
Date date1 = sdf. parse (source );
Return date1;
}
}
This article from the "mainstream heart" blog, please be sure to keep this source http://csdnchong.blog.51cto.com/7803394/1297941