计算最后一个星期日前一周,从今天到上个星期日 [英] Calculate 1 week before the last Sunday and from today to last Sunday

查看:130
本文介绍了计算最后一个星期日前一周,从今天到上个星期日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MySQL表中存储了几天和几个小时的时间戳。我现在要做的是每天检索一个特定用户从上周日到星期天(工作一周)之间的工作。而另一个选项是从今天直到上个星期日(当前周)的每天检索。有些员工每天都不工作。

I am storing some days and hours as timestamp in my MySQL table. What I want to do now is retrieve every day that a specific user worked from last Sunday until the Sunday before (One week of work). And the other option is retrieve every day from today until last Sunday (current week). Some employees does not work everyday.

我不知道我如何在Java中编写这个代码,或者是否有一个特定的MySQL函数。

I don't know how I can code this in Java or whether there is a specific MySQL function.

推荐答案

,您可以将Calendar类用于查找上一个星期天:

in Java, you can put the Calendar class to good use to find the previous Sunday :

日历c =日历;

c.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);

日期lastSunday = c.getTime();

然后可以减少以1 WEEK_OF_MONTH查找之前的星期天:

you can then decrement by 1 WEEK_OF_MONTH to find the Sunday before that :

c.add(Calendar.WEEK_OF_MONTH,-1);

日期sundayBeforeThat = c.getTime();

这篇关于计算最后一个星期日前一周,从今天到上个星期日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆