Calendar.WEEK_OF_MONTH给出了两个不同的设备不同的结果 [英] Calendar.WEEK_OF_MONTH gives different results on two different devices

查看:532
本文介绍了Calendar.WEEK_OF_MONTH给出了两个不同的设备不同的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个设备HTC采用Android 2.3.5和三星与2.3.6
现在我面临的问题是
我需要一个月的日期的一周。

所以我写了这个code和上都安装了电话。并设置系统日期为


  

2013年1月27日


 日历日历= Calendar.getInstance();
  INT weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
  Log.i(TAGweekOfMonth =+ weekOfMonth);

现在HTC输出

  weekOfMonth = 5

而三星运行相同的code生产

  weekOfMonth = 4

这真的是提前拧我的逻辑N次计算。

我是做错了什么?


解决方案

这可能是由于语言环境。在Java

 日历calFr = Calendar.getInstance(TimeZone.getTimeZone(欧洲/巴黎),Locale.FRANCE);
        日历calUs = Calendar.getInstance(TimeZone.getTimeZone(US /东航),Locale.US);
        日历calUk = Calendar.getInstance(TimeZone.getTimeZone(GMT),Locale.UK);
        calFr.set(2013年,Calendar.JANUARY,27);
        calUs.set(2013年,Calendar.JANUARY,27);
        calUk.set(2013年,Calendar.JANUARY,27);        INT weekOfMonthFr = calFr.get(Calendar.WEEK_OF_MONTH);
        INT weekOfMonthUs = calUs.get(Calendar.WEEK_OF_MONTH);
        INT weekOfMonthUk = calUk.get(Calendar.WEEK_OF_MONTH);
        的System.out.println(月的法国周是+ weekOfMonthFr);
        的System.out.println(月的美国一周+ weekOfMonthUs);
        的System.out.println(月英国本周是+ weekOfMonthUk);

会给你

 本月法国周是4
本月美国本周是5
本月英国本周是4

I have two devices HTC with android 2.3.5 and Samsung with 2.3.6 now the problem i am facing is i need the date's week of month.

So i've written this code and installed on both the phones. and set the system date as

27th Jan 2013

  Calendar calendar = Calendar.getInstance();
  int weekOfMonth =  calendar.get(Calendar.WEEK_OF_MONTH);
  Log.i(TAG,"weekOfMonth = "+weekOfMonth);

now on HTC the output is

 weekOfMonth = 5

while on samsung running the same code produces

 weekOfMonth = 4

this really is screwing my logic n calculations ahead.

am i doing something wrong ?

解决方案

It is probably due to Locales. In Java

        Calendar calFr = Calendar.getInstance(TimeZone.getTimeZone("Europe/Paris"), Locale.FRANCE);
        Calendar calUs = Calendar.getInstance(TimeZone.getTimeZone("US/Eastern"), Locale.US);
        Calendar calUk = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.UK);
        calFr.set(2013, Calendar.JANUARY, 27);
        calUs.set(2013, Calendar.JANUARY, 27);
        calUk.set(2013, Calendar.JANUARY, 27);

        int weekOfMonthFr = calFr.get(Calendar.WEEK_OF_MONTH);
        int weekOfMonthUs = calUs.get(Calendar.WEEK_OF_MONTH);
        int weekOfMonthUk = calUk.get(Calendar.WEEK_OF_MONTH);
        System.out.println("France week of month is " + weekOfMonthFr);
        System.out.println("USA week of month is " + weekOfMonthUs);
        System.out.println("UK week of month is " + weekOfMonthUk);

will give you

France week of month is 4
USA week of month is 5
UK week of month is 4

这篇关于Calendar.WEEK_OF_MONTH给出了两个不同的设备不同的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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