【问题标题】:JavaScript to JQuery; formatting date for MySQLJavaScript 到 JQuery; MySQL的格式化日期
【发布时间】:2016-08-06 09:43:27
【问题描述】:

经过反复试验,我终于让我的日历按照我想要的方式运行了。我只允许选择某个时间段。无论当前日期是什么,它都在 10 到 21 天之间。但是,我将这个新日历插入到预先存在另一个日历的插槽中,并且我需要根据之前的设置方式确保这些值正确传递到 MySQL。

以前存在的代码是 JavaScript,我将其更改为 JQuery。之前的代码中有这一行:

dateFormat: 'yy-mm-dd' // MySQL datetime format 

现在,如果可能,我希望我的新日历使用相同的日期格式。

$(document).ready(function () {
   $('.txtDeadline').datepicker({ minDate: +10, maxDate: +21 });
  });


// Still needs dateFormat: 'yy-mm-dd' for MySQL datetime format
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<head>
<link href="//code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
</head>



<div class="clear">
	<label for="txtDeadline">Deadline<span class="required">*</span></label>
	<div class="input">
		<input class="txtDeadline" name="txtDeadline" type="text" />
		<p>Min: 10 days Max: 21 days from current date</p>
	</div>
</div>

【问题讨论】:

    标签: javascript jquery datetime datepicker datetime-format


    【解决方案1】:

    $(document).ready(function () {
       $('.txtDeadline').datepicker({ minDate: +10, maxDate: +21,dateFormat: 'yy-mm-dd' });
      });
    
    
    // Still needs dateFormat: 'yy-mm-dd' for MySQL datetime format
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <head>
    <link href="//code.jquery.com/ui/1.9.2/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="//code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    </head>
    
    
    
    <div class="clear">
    	<label for="txtDeadline">Deadline<span class="required">*</span></label>
    	<div class="input">
    		<input class="txtDeadline" name="txtDeadline" type="text" />
    		<p>Min: 10 days Max: 21 days from current date</p>
    	</div>
    </div>

    【讨论】:

    • 非常感谢您的帮助!
    • 很高兴为您提供帮助
    猜你喜欢
    • 1970-01-01
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-20
    • 1970-01-01
    相关资源
    最近更新 更多