根据android中的日期查找一天
我有 2 个问题:
如何根据 JAVA 中的特定日期查找星期几?
我想在Java或PHP中找到2次(每次包括日期和小时)之间的差异,有人可以帮助我吗?
谢谢,
编辑: 我仍然有一个问题,我没有成功找到特定日期的日期...我正在尝试两种方法,两种方法都不起作用。
1.
GregorianCalendar g = new GregorianCalendar(year, month, day, hour, min);
int dayOfWeek=g.DAY_OF_WEEK;
2.
Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, min);
int dayOfWeek2 = cal.get(Calendar.DAY_OF_WEEK);
有人能给我另一个解决方案吗?
I have 2 questions:
How can I find what is the day of the week according to a specific date in JAVA ?
I want to find a difference between 2 times (each time include date and hour) in Java or PHP, someone can help me with that?
Thanx,
EDIT:
I still have a problem with that, I dont success to find the date of a specific date... i'm trying 2 ways, boths are not working.
1.
GregorianCalendar g = new GregorianCalendar(year, month, day, hour, min);
int dayOfWeek=g.DAY_OF_WEEK;
2.
Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, min);
int dayOfWeek2 = cal.get(Calendar.DAY_OF_WEEK);
Someone cane give me another solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然不是特别好,但标准 Java
Calendar
类应该足以解决您的第一个问题。您可以使用 Date 对象设置 Calendar 实例的时间,然后访问 DAY_OF_WEEK 字段。是这样的:至于第二个问题,这取决于你想要如何衡量差异。如果您只需要以毫秒为单位的差异,则只需对每个 Date 实例调用 getTime() 方法,然后将其中一个减去另一个即可。如果您想要以秒、分钟、小时、天等形式表示,您可以简单地使用该值进行一些简单的算术运算。
While not particularly great, the standard Java
Calendar
class should be sufficient for solving your first problem. You can set the time of a Calendar instance using a Date object, then access the DAY_OF_WEEK field. Something like this:As for the second problem, it depends how you want the difference to be measured. If you just want the difference in milliseconds, you can simply call the
getTime()
method on each of your Date instances, and subtract one from the other. If you want it in terms of seconds, minutes, hours, days, etc you can simply do some simple arithmetic using that value.请参阅这些链接,
查找星期几
根据查找星期几对于特定日期,
请尝试如下所示,
找出两个之间的差异次
Refer these links,
Find day of the week
to find the day of the week according to a specific date
try like below,
Find the difference between two times