我试图找到第二天使用javascript它为静态日期完美的工作,但没有工作的动态日期。如何找到第二天使用javascript
1日期间的工作还到12,给我完美的输出吧,高日不工作,然后12
请帮我解决这个问题!
<script type="text/javascript">
function next_day() { \t
\t // var date = document.getElementById('date').value;
\t var textbox_Value = document.getElementById('date').value;
\t console.log("input date : " + textbox_Value);
\t var fDate = new Date(textbox_Value.replace(/(\d{2})-(\d{2})-(\d{4})/, "$2/$1/$3")); //change date formate mm/dd/yyyy to dd/mm/yyyy
\t var dayWithSlashes = (fDate.getDate()) + '/' + (fDate.getMonth()+1) + '/' + fDate.getFullYear();
\t console.log("Foramat changed date : " + dayWithSlashes);
\t var day_in_js_format = new Date(dayWithSlashes);
\t console.log("convert in date format : " + day_in_js_format);
\t day_in_js_format.setDate(day_in_js_format.getDate() + 1);
\t console.log("day_in_js_format++ : " + day_in_js_format);
\t var final_Result = (day_in_js_format.getDate()) + '/' + (day_in_js_format.getMonth()+1) + '/' + day_in_js_format.getFullYear();
\t console.log("next day : " + final_Result);
}
</script>
<!DOCTYPE html>
<html>
<head>
\t <title>
\t \t Next day using javascript
\t </title>
\t <!-- Latest compiled and minified CSS & JS -->
\t <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
\t <div class="container fix-top">
\t \t <form action="" method="POST" role="form">
\t \t \t <legend>Form title</legend>
\t \t
\t \t \t <div class="form-group">
\t \t \t \t <label for="">Next day</label>
\t \t \t \t <input type="text" class="form-control" id="date" name="date" placeholder="Input field">
\t \t \t </div> \t \t \t
\t \t
\t \t \t <button type="button" onclick="next_day();" class="btn btn-primary">Submit</button>
\t \t </form>
\t </div>
\t
\t <script src="//code.jquery.com/jquery.js"></script>
\t <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
</body>
</html>
症状表明,创建日期时您已将月份和日期混合在一起... – Teemu
构建日期对象时,不要使用非标准的dd/mm/yyyy格式。改为使用yyyy-mm-dd。 – JJJ
我没有混合月份和日期你请检查你的日志以便更好地了解 – HirenMangukiya