Questions about how to add an end time to a form validation control in a Web project that is not less than the start time, between the date conversion and the foreground display format, and the JSON date data format converted to a standard date format

Source: Internet
Author: User
Tags string format time and seconds

The date display format is different between the different pages in the project,

First question:

For example, I use the date control wdatepicker.js only in the input tag to add onclick= "Wdatepicker ()" can be used, but the default is no time and seconds, if needed to display the minute and seconds only need to add Wdatepicker ({ DATEFMT: ' Yyyy-mm-dd HH:mm:ss '}) on the line.

**************************************************************************************************************

Second question:

Then I use the form validation control jquery.validate.js need to compare the end time must be greater than the start time, this needs to add a method, JS can write:

<script type= "Text/javascript" src= "Js/jquery.validate.js" ></script>

<script type= "Text/javascript" >

This method is the date format of the day of the month of the conversion,
function GetDate (strdate) {
var date = eval (' New Date ' ('
+ Strdate.replace (/\d+ (? =-[^-]+$)/, function (a) {
Return parseint (A, 10)-1;
}). Match (/\d+/g) + ') ';
return date;
}

JQuery.validator.addMethod ("FDate", function (value, element, param) {

"FDate" is the method name, which needs to be verified at the end time after both the start and end times are entered ETime

Value is the values of the elements, element is the elements themselves param are parameters
var end = GetDate (value);
var begin = GetDate ($ ("#" +param). Val ());
if (Begin > End) {
return false;
}
return true;
}, $.validator.format ("The end time cannot be less than the start date");

$ (function () {

Rules: {

Name: {

Required:true,

Minlength:5

},

Qipai: {

Required:true,

Number:true

},

Dijia: {

Required:true,

Number:true

},

Stime: {

Required:true,

Dateiso:true

},

ETime: {

Required:true,

Dateiso:true,

FDate: "Stime"//"Stime" when the parameters are passed in, plus a "#" Stime.val () can take the value of my start time

}

},

Messages: {

Name: {

Required: "Product name must be filled",

Minlength:jQuery.format ("User name cannot be less than {0} characters")

},

Qipai: {

Required: "Starting price must be filled",

Number: "Must be a numeric type"

},

Dijia: {

Required: "Reserve price must be filled",

Number: "Must be a numeric type"

},

Stime: {

Required: "Start date is required",

Dateiso:true

},

ETime: {

Required: "The end date is required",

Dateiso:true

}

}

});

});

In contrast to my HTML tags:

Start time: <input type= "text" name= "stime" id= "Stime"
Onclick= "Wdatepicker ()" value= "<fmt:formatdate value= ' ${ugood.stime} ' pattern= ' Yyyy-mm-dd '/> ' ><br>
End time: <input type= "text" name= "etime" id= "ETime"
Onclick= "Wdatepicker ()" value= "<fmt:formatdate value= ' ${ugood.etime} ' pattern= ' Yyyy-mm-dd '/> ' ><br>

***********************************************************************************************

Question three:

My Oracle database is a date type, due to the need for accurate dates, my Javebean date type is timestamp type can be accurate to the time and seconds, then I query the page according to the date of the publication of the product does not need to be accurate to the time and seconds, What do I do when my input tag reads a value from the database and then displays it in seconds?

You can add instructions at the top of the JSP page <%@ taglib prefix= "FMT" uri= "Http://java.sun.com/jsp/jstl/fmt"%>

In the tag:: <input type= "text" name= "stime" id= "Stime"
Onclick= "Wdatepicker ()" value= "<fmt:formatdate value= ' ${ugood.stime} ' pattern= ' Yyyy-mm-dd '/> ' > It only shows the format of the month and day.

***********************************************************************************************************

Fourth question, when I use AJAX to fetch data from the background, I need to convert the entity class information into the JOSN format, so the problem I have is that the JSON control combines with the cascade in Hibernate,

My Precord record class corresponds to the goods class and the user class are many-to-one relationships, Precord class has

@ManyToOne (fetch = Fetchtype.eager)
@JoinColumn (name = "USERID")
Private Puser Puser;

And

@ManyToOne (fetch = Fetchtype.eager)
@JoinColumn (name = "GID")
Private Goods Goods;

and the goods class and the user class also have a one-to-many relationship,

@OneToMany (cascade = cascadetype.all, fetch = fetchtype.lazy, Mappedby = "goods")
Private set<precord> precords = new hashset<precord> (0);

And

@OneToMany (cascade = cascadetype.all, fetch = fetchtype.lazy, Mappedby = "Puser")
Private set<precord> precords = new hashset<precord> (0);

On-line search and investigate the solution to:

Jsonarray array = new Jsonarray ();

Jsonconfig config = new Jsonconfig ();

Config.registerjsonvalueprocessor (Timestamp.class,new jsondatevalueprocessor ());

Config.setjsonpropertyfilter (New PropertyFilter () {

@Override

public Boolean apply (object arg0, String name, object arg2) {

if (Name.equals ("Precords")) {

return true;

}

return false;

}

});

So the JSON is out.

But again, the time-type format that my JSON reads is:

"Ptime": {"date": Max, "Day": 0, "hours":, "Minutes": 5, "month": Ten, "Nanos": 0, "seconds":, "Time": 1416755159000, " Timezoneoffset ": -480," Year ": 114}

Then the forward platform to the time of the effort, the online search method:

In the code that just filtered the dead loop, the comment is removed and can be used.

Config.registerjsonvalueprocessor (Timestamp.class,new jsondatevalueprocessor ());

The new Jsondatevalueprocessor () class in this code is the class that implements the Jsonvalueprocessor interface in its own handwriting, and the specific code in the class is:

public class Jsondatevalueprocessor implements Jsonvalueprocessor {private String format = "Yyyy-mm-dd HH:mm:ss";

Public Jsondatevalueprocessor () {//TODO auto-generated constructor stub}

@Override
public object Processarrayvalue (object value, Jsonconfig jcf) {
string[] obj = {};
if (value instanceof date[]) {
SimpleDateFormat SDF = new SimpleDateFormat (format);
date[] dates = (date[]) value;
obj = new String[dates.length];
for (int i = 0; i < dates.length; i++) {
Obj[i] = Sdf.format (Dates[i]). Trim ();
}
}
return obj;
}

@Override public Object Processobjectvalue (String key, object value, Jsonconfig jcf) {

if (value instanceof Date) {

String str = new SimpleDateFormat (format). Format ((Date) value);

return Str.trim ();

}

return value = = null? Null:value.toString ();

}

}

So the time is converted into the format you want:

"Ptime": "2014-11-23 23:05:59"

Questions about how to add an end time to a form validation control in a Web project that is not less than the start time, between the date conversion and the foreground display format, and the JSON date data format converted to a standard date format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.