亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將日期格式從 MM/DD/YYYY 編輯為 DD/MM/YYY

將日期格式從 MM/DD/YYYY 編輯為 DD/MM/YYY

慕神8447489 2023-09-14 20:40:00
所以我編寫了一些代碼,允許某人輸入他們的訂單日期并返回預期的打印和交貨日期。唯一的問題是它拆分了 MM/DD/YYYY。非常感謝任何幫助使這項工作正常進行。<head>  <meta charset="utf-8">  <meta name="viewport" content="width=device-width, initial-scale=1">  <title>jQuery UI Datepicker - Default functionality</title>  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">  <link rel="stylesheet" href="/resources/demos/style.css">  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>  <script>    $(function() {      $("#datepicker").datepicker();    });  </script>  <script>    function myfunction() {      var future = new Date(document.getElementById("datepicker").value); // get today date      future.setDate(future.getDate() + 7); // add 7 days      var finalDate = future.getFullYear() + '-' + ((future.getMonth() + 1) < 10 ? '0' : '') + (future.getMonth() + 1) + '-' + future.getDate();      var future2 = new Date(document.getElementById("datepicker").value);      future2.setDate(future2.getDate() + 10); // add 7 days      var finalDate2 = future.getFullYear() + '-' + ((future2.getMonth() + 1) < 10 ? '0' : '') + (future2.getMonth() + 1) + '-' + future2.getDate();      alert('Your order will be printed on ' + finalDate + '\nYou should recieve your order ' + finalDate2);    }  </script></head><body>  <form onSubmit="myfunction()">    <p>Date: <input type="text" id="datepicker" name="date"></p>    <input type="submit" lable="Submit">    <p id="demo"></p>  </form></body></html>
查看完整描述

1 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

我在您的代碼上以日期格式進行編輯:var finalDate和var finalDate2。因為在代碼中在 jquery 中設置了日期格式。


在下面的代碼中,將日期格式更改為 DD/MM/YYYY

所以我更改為以下代碼:


var finalDate = future.getDate() +'-'+ ((future.getMonth() + 1) < 10 ? '0' : '') + (future.getMonth() + 1) +'-'+future.getFullYear();


var finalDate2 = future2.getDate() +'-'+ ((future2.getMonth() + 1) < 10 ? '0' : '') + (future2.getMonth() + 1) +'-'+ future.getFullYear();

然后會得到這樣的輸出


<head>

  <meta charset="utf-8">

  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>jQuery UI Datepicker - Default functionality</title>

  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

  <link rel="stylesheet" href="/resources/demos/style.css">

  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>

  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

  <script>

  $( function() {

    $( "#datepicker" ).datepicker({

        dateFormat: 'dd/mm/yy'

    });

  });

  </script>

    

    <script>

        

        

function myfunction(){


    var future = new Date(document.getElementById("datepicker").value); // get today date

future.setDate(future.getDate() + 7); // add 7 days

    

    var finalDate = future.getDate() +'-'+ ((future.getMonth() + 1) < 10 ? '0' : '') + (future.getMonth() + 1) +'-'+future.getFullYear();

    

    var future2 = new Date(document.getElementById("datepicker").value);

    future2.setDate(future2.getDate() + 10); // add 7 days

    

    var finalDate2 = future2.getDate() +'-'+ ((future2.getMonth() + 1) < 10 ? '0' : '') + (future2.getMonth() + 1) +'-'+ future.getFullYear();

    

        


    alert('Your order will be printed on ' + finalDate  + '\nYou should recieve your order ' + finalDate2);

}

    </script>

</head>

<body>

 <form onSubmit="myfunction()">

<p>Date: <input type="text" id="datepicker" name="date"></p>

 <input type="submit" lable="Submit">

     

     <p id="demo"></p>


    </form>

    

    

    

</body>

</html>

更新

將輸入格式更改為 DD/MM/YYYY

改變了


$( "#datepicker" ).datepicker();


$( "#datepicker" ).datepicker({

   dateFormat: 'dd/mm/yy'

});


查看完整回答
反對 回復 2023-09-14
  • 1 回答
  • 0 關注
  • 100 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號