How can I get current date in Android?

前端 未结 26 2059
[愿得一人]
[愿得一人] 2020-11-27 10:24

I wrote the following code

Date d = new Date();
CharSequence s  = DateFormat.format(\"MMMM d, yyyy \", d.getTime());

But is asking me para

26条回答
  •  失恋的感觉
    2020-11-27 11:12

    just one line code to get simple Date format :

    SimpleDateFormat.getDateInstance().format(Date())
    

    output : 18-May-2020

    SimpleDateFormat.getDateTimeInstance().format(Date())
    

    output : 18-May-2020 11:00:39 AM

    SimpleDateFormat.getTimeInstance().format(Date())
    

    output : 11:00:39 AM

    Hope this answer is enough to get this Date and Time Format ... :)

提交回复
热议问题