Android get current date and show it in TextView

前端 未结 10 2148
清歌不尽
清歌不尽 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:46

    I suggest:

    long date = System.currentTimeMillis(); 
    
    SimpleDateFormat sdf = new SimpleDateFormat("MMM MM dd, yyyy h:mm a");
    String dateString = sdf.format(date);   
    tvDisplayDate.setText(dateString);
    

    which displays in the following example format

    Mon Jan 5, 2009 4:55 PM

    You can use whatever format you want - options can be found at Oracle

提交回复
热议问题