为什么我没有获得设置此日历对象的星期几? [英] Why am I not getting the day of the week I expect from setting this calendar object?

查看:173
本文介绍了为什么我没有获得设置此日历对象的星期几?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:谢谢 - 我现在明白了很多。它很混乱,当你第一次开始!谢谢您的帮助。我要保持这个问题,因为它可能帮助别人(在更多的downvote的危险)。还有一些其他图书馆,每个人似乎推荐的日期时间

Thanks- I understand it a lot more now. Its very confusing when you first start! Thanks for the help. I am going to keep the question up as is ( in peril of more downvotes) as it might help others. There are some other libraries that everyone seems to recommend for date time

我努力的Java日历功能 - 要返回错误的数据,底部的数字应该是一个星期四根据日历,但作为一个星期六返回!

I am struggling with the Java calendar function- its seems to be returning wrong data the bottom figure should be a thursday according to calendar, but is returning as a saturday!

Calendar cal = new GregorianCalendar();
       cal.set(2012,2,23); // 0 = January

      String weekdays[]={"sunday","monday", "tuesday", "wednesday","thursday","friday","saturday",};

        Integer Weekdaycurrent1=cal.get(Calendar.DAY_OF_WEEK);
        System.out.println("today is a "+weekdays[Weekdaycurrent1]); //Prints today is Saturday, when it should be a thursday


推荐答案

p>首先, DAY_OF_WEEK 1

public final static int SUNDAY = 1;

其次, 2012-03-23

您的代码运行正常。

编辑:对于那些无法正确阅读问题,调用 cal.set(2012,2,23)将日期设置为 2012-03-23 ,因为 month 参数为零(即Jan = 0,Feb = 1,Mar = 2等)

Edited: For those too lame to read the question properly, calling cal.set(2012,2,23) sets the date to 2012-03-23, because the month parameter is zero-based (ie Jan = 0, Feb = 1, Mar = 2, etc)

这篇关于为什么我没有获得设置此日历对象的星期几?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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