这是我的2日期
<EditText
android:background="@drawable/text_underscore_line"
... />
我想在这两个日期之间循环。所以,我确实喜欢这个
var startdate = '11-12-2016';
var stopdate = '13-12-2016';
但是我在浏览器中运行无限循环。
我该怎么做。
注意:
我不想在这个问题上使用jQuery。
如果开始和结束日期相同,则它应仅循环一次,输入日期将始终为d / m / y格式。我的代码中有什么错误。请帮忙
更新:
我弄错了日期格式,我的日期格式是d-m-y。我怎么能为一个人做这个...
答案 0 :(得分:1)
使用startdateArr = startdate.split('-');
stopdateArr = stopdate.split('-');
var startMedicine = new Date(startdateArr[2],startdateArr[1]-1,startdateArr[0]);
var stopMedicine = new Date(stopdateArr[2],stopdateArr[1]-1,stopdateArr[0]);
// thanks RobG for correcting on month index
while(startMedicine <= stopMedicine){
var v = startMedicine.getDate() + '-' + (startMedicine.getMonth() + 1) + '-' + startMedicine.getFullYear();
console.log(v);
startMedicine.setDate(startMedicine.getDate()+1);
}
getMonth() + 1
在js月份,索引从0开始,因此nov是10 dec。是11,喜欢这就是为什么我使用 <?php
if(isset($_POST['delete']))
{
setcookie("names",0, 1);
setcookie("flavors",0, 1);
setcookie("scoops",0, 1);
header("Location: coookie.php");
exit();
}
if(isset($_POST['name'])&& ($_POST['flavor']) && ($_POST['scoop']))
{
setcookie("names", $_POST['name']);
setcookie("flavors", $_POST['flavor']);
setcookie("scoops", $_POST['scoop']);
header("Location: coookie.php");
exit();
}
if(!isset($_COOKIE['names']) &&($_COOKIE['flavors']) &&($_COOKIE['scoops']))
{
echo<<<_END
<form action="coookie.php" method="post"><pre>
enter your name.
Name <input type="text" name="name">
</br>
Select Your Flavor
<select name="flavor">
<option value="choco">Chocolate</option>
<option value="van">Vanilla</option>
</select>
</br>
<input type="radio" name="scoop" value="single" checked> Single Scoop<br>
<input type="radio" name="scoop" value="double"> Double Scoop<br>
<input type="submit" value="Submit"></pre>
</form>
_END;
}
else
{
$name=$_COOKIE['names'];
$flavor=$_COOKIE['flavors'];
$scoop=$_COOKIE['scoop'];
echo<<<_END
hi $name Your order of $scoop $flavor ice-cream is on the way!
<form action="coookie.php" method="post">
<input type="hidden" value="yes" name="delete">
<input type="submit" value="delete">
</body>
_END;
}
?>
`
答案 1 :(得分:0)
主要问题是您没有增加日期。
这是解决方案
var startdate = '11/12/2016';
var stopdate = '11/13/2016';
var startMedicine = new Date(startdate);
var stopMedicine = new Date(stopdate);
var currentMedicine = startMedicine;
var dayCount = 0;
while(currentMedicine < stopMedicine){
currentMedicine.setDate(startMedicine.getDate() + dayCount);
// You can replace '/' to '-' this if you want to have dd-mm-yyyy instead of dd/mm/yyy
var currentDate = currentMedicine.getDate() + '/' + (currentMedicine.getMonth() + 1) + '/' + currentMedicine.getFullYear(); // in dd/mm/yyyy format
console.log(currentDate);
dayCount++;
}
答案 2 :(得分:0)
你可以利用时刻js和时刻js的持续时间。它仅用于持续时间目的。它非常容易并且意味着相同。