Java 字符串中的星期几
我有这个简单的代码:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse("2011-10-29");
calendar.setTime(date);
Log.d("Debug","Day of the week = "+(calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY));
10 月 29 日是星期六,为什么我会得到错误的结果?
I have this simple code:
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date date = format.parse("2011-10-29");
calendar.setTime(date);
Log.d("Debug","Day of the week = "+(calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY));
The 29th of October is a Saturday so why do I get false?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个如何发生这种情况的示例......
输出
是的,取决于您所在的时区是否是星期六。
Here is an example of how this could happen...
which outputs
so yes, depending on what time zone you are in it will or will not be Saturday.
使用以下代码即可实现:
也许是区域设置?
Getting true with the following code:
Maybe a locale setting?