我有这个数组了几天:
var dates = [
/* 2016 */
"October 28, 2016","November 17, 2016","December 24, 2016","December 25, 2016","December 26, 2016",
/* 2017 */
"January 1, 2017","March 3, 2017","April 17, 2017","May 1, 2017","May 8, 2017","July 5, 2017","July 6, 2017","September 28, 2017","October 28, 2017","November 17,2017","December 24, 2017","December 25, 2017","December 26, 2017"
]
我希望他们与明天的日期比较,所以我明天创建了变量
var tomorrow = new Date();
tomorrow .setDate(tomorrow.getDate() + 1);
tomorrow .setHours(0);
tomorrow .setMinutes(0);
tomorrow .setSeconds(0);
tomorrow .setMilliseconds(0);
当我尝试dates.indexOf(tomorrow)
时,我得到结果-1
。
tomorrow
的值为Fri Oct 28 2016 00:00:00 GMT+0200 (Střední Evropa (letní čas))
编辑:我将日期数组更改为
var dates = [
/* 2016 */
new Date("October 28, 2016"), new Date("November 17, 2016"), new Date("December 24, 2016"), new Date("December 25, 2016"), new Date ("December 26, 2016"),
/* 2017 */
new Date("January 1, 2017"), new Date("March 3, 2017"), new Date("April 17, 2017"), new Date("May 1, 2017"), new Date("May 8, 2017"), new Date("July 5, 2017"), new Date("July 6, 2017"), new Date("September 28, 2017"), new Date("October 28, 2017"), new Date("November 17,2017"), new Date("December 24, 2017"), new Date("December 25, 2017"), new Date("December 26, 2017")
]
现在当我将tomorrow
的值Fri Oct 28 2016 00:00:00 GMT+0200 (Střední Evropa (letní čas))
与函数dates.indexOf(tomorrow)
进行比较时,我仍然得到-1
个结果。
dates[0]
值为Fri Oct 28 2016 00:00:00 GMT+0200 (Střední Evropa (letní čas))
tomorrow
的值为Fri Oct 28 2016 00:00:00 GMT+0200 (Střední Evropa (letní čas))
同样,为什么结果不是0
?
答案 0 :(得分:2)
您可以像这样创建日期变量:
@RequestMapping(value = "/public/validatepassword", method = RequestMethod.POST)
public String validateUsernameAndPassword(Model model, @ModelAttribute LoginBeanDTO loginDto,
HttpServletRequest request, HttpServletResponse response) {
HttpSession session = request.getSession();
String requestFrom = request.getParameter("requestFrom");
if (requestFrom != null && requestFrom != "" && requestFrom.equalsIgnoreCase("requestFromOtherSource")) {
String userId = request.getParameter("username");
String password = request.getParameter("password");
loginDto.setUsername(userId);
loginDto.setPassword(password);
session.setAttribute("fromOtherResource", requestFrom);
}
if (!userCmdHelper.validateUsernameAndPassword(loginDto)) {
model.addAttribute("loginDto", loginDto);
model.addAttribute("error", "Invalid username or password");
return "login";
} else {
session.setAttribute("j_username", loginDto.getUsername());
session.setAttribute("j_password", loginDto.getPassword());
return "loginRedirector";
}
}
在您的代码中,而不是<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
// This is to prevent Caching on the browser and proxy
response.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
response.setHeader("Pragma", "no-cache"); //HTTP 1.0
response.setDateHeader("Expires", -1); //prevents caching at the proxy server
%>
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragmas" content="no-cache">
<script type="text/javascript">
function redirect() {
document.jsecuritycheck.submit();
}
</script>
</head>
<body class="default" marginheight="0" marginwidth="0" topmargin="0"
leftmargin="0" onLoad="redirect();">
<form
action="<c:url value="${pageContext.request.contextPath}"/>/j_spring_security_check"
method="POST" name="jsecuritycheck">
<c:set var="username" value="${j_username}" />
<c:set var="password" value="${j_password}" />
<input type="hidden" name="j_username"
value="<c:out value="${username}"/>" escapeXml="true"> <input
type="hidden" name="j_password" value="<c:out value="${password}"/>"
escapeXml="true">
</form>
</body>
</html>
,您应该var date = new Date("October 28, 2016")
EDIT 要将日期数组转换为日期变量,您只需要调用一个循环(&#34;对于&#34;,&#34;而#34;)或从数组中读取一个映射,如下所示:
tomorrow .setDate(zitrek.getDate() + 1);