[Jquery Date Processing] Select Start Time and automatic End Time

Source: Internet
Author: User
Tags js function declaration

For example, if you select start time, the end time is automatically assigned a value.

1. Page Introduction <SCRIPT type = "text/JavaScript" src = "../styles/JS/jquery-1.6.2.js"> </SCRIPT>

2. HTML code

<Tr> <TD class = "category"> Start Time: </TD> <input id = "starttime" name = "starttime" type = "text" onclick = "wdatepicker ({startdate: 'Current time', datefmt: 'yyyy-mm-dd hh: mm: ss'}) "onchange =" addhours (this. value) "/> <font color =" # ff0000 "> * </font> </TD> <TD class =" category "> End Time: </TD> <input id = "endtime" name = "endtime" type = "text" onclick = "wdatepicker ({startdate: 'Current time', datefmt: 'yyyy-mm-dd hh: mm: ss'}) "/> <font color =" # ff0000 "> * </font> </TD> </tr>

3. Redefinition of date objects

// Time format date. Prototype. format = function (Format) {/** eg: format = "yyyy-mm-dd hh: mm: SS"; */If (! Format) {format = "yyyy-mm-dd hh: mm: SS";} var o = {"m +": This. getmonth () + 1, // month "d +": This. getdate (), // Day "H +": This. gethours (), // Hour "m +": This. getminutes (), // minute "s +": This. getseconds (), // second "q +": math. floor (this. getmonth () + 3)/3), // quarter "S": This. getmilliseconds () // millisecond}; If (/(Y + )/. test (Format) {format = format. replace (Regexp. $1, (this. getfullyear ( ) + ""). Substr (4-Regexp. $1. length);} For (var k in O) {If (New Regexp ("(" + K + ")"). test (Format) {format = format. replace (Regexp. $1, Regexp. $1. length = 1? O [k]: ("00" + O [k]). substr ("" + O [k]). Length) ;}} return format ;};

4. js function declaration

function addHours(startTime){var start=new Date(startTime.replace("-", "/").replace("-", "/"));start.setHours(start.getHours()+2);$("#endTime").val(start.format("yyyy-MM-dd hh:mm:ss"));}

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.