gpt4 book ai didi

android - datePicker.getMonth() +1 没有给出预期的结果

转载 作者:行者123 更新时间:2023-11-29 14:29:07 27 4
gpt4 key购买 nike

             Toast.makeText(getBaseContext(),
"Date selected:" + datePicker.getMonth()+1+
"/"+ datePicker.getDayOfMonth() +
"/"+ datePicker.getYear() +"\n" +
"Time Slected:" + timePicker.getCurrentHour() +
":"+ timePicker.getCurrentMinute(),
Toast.LENGTH_SHORT).show();

通过将 1 加到 datePicker.getMonth(),我得到月份数

            output like->
jan-01,feb-11,mar-21

但是当我删除“1”时,我得到的月份数字输出如下

            jan-0,feb-01,mar-02

最佳答案

你需要括号。

(datePicker.getMonth()+1)

否则你就是在进行字符串连接。

例如

如果 getMonth() 返回 0(一月),则

"Date selected: " + datePicker.getMonth()+1

("Date selected: " + 0) + 1
= "Date selected: 0" + 1
= "Date selected: 01"

但是有 parent

"Date selected: " + (datePicker.getMonth()+1)
= "Date selected: " + (0+1)
= "Date selected: " + 1
= "Date selected: 1"

关于android - datePicker.getMonth() +1 没有给出预期的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6971439/

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