如何获得上周一的日期

hellobb 2002-12-20 12:49:13
不是本周一。
...全文
56 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hellobb 2002-12-20
  • 打赏
  • 举报
回复
非常感谢,接分
emu 2002-12-20
  • 打赏
  • 举报
回复
呵呵,真的很抱歉,java里面的年要加1900的:

<%@ page import="java.util.Date"%>
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<TITLE> emu's test </TITLE>
</HEAD>
<BODY>
<%
Date d = new Date();
d = new Date(d.getYear(),d.getMonth(),d.getDate()-d.getDay()-6);
%>
<%=d.getYear()+1900%>年<%=d.getMonth()+1%>月<%=d.getDate()%>日 星期<%=d.getDay()%>
</BODY>
</HTML>
emu 2002-12-20
  • 打赏
  • 举报
回复
抱歉,写错了。月份应该加1的:

var d = new Date();
var d = new Date(d.getFullYear(),d.getMonth(),d.getDate()-d.getDay()-6)
alert(d.getFullYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日 星期"+d.getDay())

jsp的写法是这样:


<%@ page import="java.util.Date"%>
<HTML>
<HEAD>
<TITLE> emu's test </TITLE>
</HEAD>
<BODY>
<%
Date d = new Date();
d = new Date(d.getYear(),d.getMonth(),d.getDate()-d.getDay()-6);
out.println(d.getYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日 星期"+d.getDay());
%>
</BODY>
</HTML>
emu 2002-12-20
  • 打赏
  • 举报
回复
var d = new Date();
var d = new Date(d.getFullYear(),d.getMonth(),d.getDate()-d.getDay()-6)
alert(d.getFullYear()+"年"+d.getMonth()+"月"+d.getDate()+"日 星期"+d.getDay())
solar 2002-12-20
  • 打赏
  • 举报
回复
1.得到当前的时间(秒) T
2.算出当前是星期几 W
3.算出上周一到今天相距的天数 D
4.从当前的时间减去D天得到上周一的时间 L = T - D * 60 * 60 * 24
5. 把L转成日期

81,116

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧