The date type is a string and a string date type, which is converted manually in Jsp/servlet and is automatically converted in struts2
SimpleDateFormat is a specific class that formats and resolves dates in a locale-related manner. It allows formatting (date-> text), parsing (text-> date), and normalization
Take a look at the converted code:
Package com.ttgbook.conver;
Import Java.text.DateFormat;
Import Java.text.SimpleDateFormat;
Import java.util.Date;
public class Conver {
//convert date to string public
static string convertostring (date date)
{
DateFormat df = new Sim Pledateformat ("Yyyy-mm-dd");
return Df.format (date);
Convert string to date public
static Date convertodate (String strdate) throws Exception
{
DateFormat df = new SimpleDateFormat ("Yyyy-mm-dd");
Return Df.parse (strdate);
}
When a string is converted to a date, an exception is thrown
DateFormat is an abstract class