gpt4 book ai didi

java - 从 calendar.getInstance 获取错误的日期

转载 作者:行者123 更新时间:2023-12-02 03:41:47 25 4
gpt4 key购买 nike

今天的日期: 2016 年 4 月 21 日星期四

Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
int weekOfDay = calendar.get(Calendar.DAY_OF_WEEK_IN_MONTH);

Utilities.trace("MainActivity, year = " + year + " month = " + month + " day = " + weekOfDay);

但结果我得到day = 3。我不明白为什么..

最佳答案

您正在打印 weekOfDay 而不是 day

Utilities.trace("MainActivity, year = " + year + " month = " + month + " day = " + weekOfDay);

更改为

Utilities.trace("MainActivity, year = " + year + " month = " + month + " day = " + day);

由于 WeekOfDay 将从 0 开始,因此周四显示为 3

关于java - 从 calendar.getInstance 获取错误的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36762338/

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