Android get current date and show it in TextView

前端 未结 10 2129
清歌不尽
清歌不尽 2021-02-14 09:23

I do not know what is wrong with code below -

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layo         


        
10条回答
  •  青春惊慌失措
    2021-02-14 09:45

    Below solution might help -

    final Calendar c = Calendar.getInstance();
    mYear = c.get(Calendar.YEAR);
    mMonth = c.get(Calendar.MONTH);
    mDay = c.get(Calendar.DAY_OF_MONTH);
    
    updateDisplay();
    
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
            // Month is 0 based so add 1
            .append(mMonth + 1).append("-")
            .append(mDay).append("-")
            .append(mYear).append(" "));
    }
    

提交回复
热议问题