Treatment of non-Strince (Date type processing)

zhaozj2021-02-16  56

Treatment of non-Strince (Date type processing)

1. Delivery of DAO layer:

/ **

* Start date conversion

* * /

SimpleDateFormat Format = New SimpleDateFormat (ApplicationConstants.date_Format);

Date datetime = format.parse ("

10/1/2003

");

Long ldate = datetime.gettime ();

Java.sql.date sqldate = new java.sql.date (ldate);

...

Ps.Setdate (NPARA , ...);

/ **

* Date conversion ends

* /

2. Treatment method of bean:

If the bean contains DATE members, two corresponding methods should be added, and examples are as follows:

/ **

* Page query termination time

* * /

Public Date getStartTime ()

{

Return DTStartTime;

}

Public void setStartTime (Date StartTime)

{

this.dtstarttime = startTime;

}

/ / Note The following two methods are to transmit and display convenient for page parameters.

Public string getendtimeString ()

{

String result = "";

IF (DTENDTIME! = NULL)

{

SimpleDateFormat Format = New SimpleDateFormat (ApplicationConstants.date_Format);

Return Format.Format (Dtendtime);

}

Return Result;

}

Public void setndTimeString (String DateString) THROWS ACTIONEXCEPTION

{

Try

{

IF (dateString! = null && dateString.Length ()> 0)

{

Dtendtime = java.sql.date.valueof (dateString);

}

Else

{

Dtendtime = NULL;

}

}

Catch (Exception Exp)

{

// The specified date string format is wrong, it should be mm / dd / yyyy

Throw new actionException ("Error.com.Cycloneqi.dateFormat.INValidate");

}

}

3. Display method of the page.

For example: Where the input date is required, the encoding is as follows:

Please enter the end time:

>

Note: Everything in this article belongs to this author of this article

转载请注明原文地址:https://www.9cbs.com/read-22525.html

New Post(0)