gpt4 book ai didi

android - Calendar.WEEK_OF_MONTH 在两种不同的设备上给出不同的结果

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:09:44 30 4
gpt4 key购买 nike

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

所以我编写了这段代码并安装在两部手机上。并将系统日期设置为

27th Jan 2013

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

现在在 HTC 上输出是

 weekOfMonth = 5

在三星上运行相同的代码会产生

 weekOfMonth = 4

这真的是在搞砸我的逻辑 n 提前计算。

我做错了什么吗?

最佳答案

这可能是由于 Locales。在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);

给你

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

关于android - Calendar.WEEK_OF_MONTH 在两种不同的设备上给出不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13276061/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com