日期选择器显示错误的月份 [英] Date picker shows wrong month

查看:120
本文介绍了日期选择器显示错误的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家可以告诉我我该怎么做才能获得正确的月份选择数,无论选择哪个月份,它总是在文本字段中少显示一个,例如,如果我选择了1997年1月1日并按好的,它将显示这样的日期:1997年1月0日,请告诉我该怎么办

Hey guys can any tell me what can I do to get the right number of month I am selecting, no matter which month I select, it always shows one less in text field for e.g if i select 1st of january 1997 and press ok it will show the date like this : 1/0/1997, please tell me what can I do

val c = Calendar.getInstance()
        c.add(Calendar.YEAR, -18)
        val year = c.get(Calendar.YEAR)
        val month = c.get(Calendar.MONTH)
        val day = c.get(Calendar.DAY_OF_MONTH)

        val abc = findViewById<Button>(R.id.birth)

        abc.setOnClickListener {

            val datePickerDialog = DatePickerDialog(
                this,
                DatePickerDialog.OnDateSetListener { view, year, month     , day ->
                    date.setText("" + day + "/" + month + "/" + year)
                },
                year,
                month,
                day
            )
            datePickerDialog.datePicker.maxDate = c.timeInMillis
            datePickerDialog.show()

        }
    }

推荐答案

安装数从零开始计数(如数组索引):

Mounts are counted from zero (like array index):

  • 一月= 0
  • 2月= 1
  • ....

如果您制作的阵列以正确的顺序包含装载名称,则日历给出的装载号就是该阵列的索引.

If you make an array that contains mount names in correct order the mount number given from calendar is the index of this array.

您可以在其中添加一个以获得真实的装载.

You can add one to it to get real mount.

这篇关于日期选择器显示错误的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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