How can I get current date in Android?

前端 未结 26 1893
[愿得一人]
[愿得一人] 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:26
     public static String getcurrentDateAndTime(){
    
            Date c = Calendar.getInstance().getTime();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
            String formattedDate = simpleDateFormat.format(c);
            return formattedDate;
        }
    
    // String currentdate=  getcurrentDateAndTime();
    
    0 讨论(0)
  • I've already used this:

    Date What_Is_Today=Calendar.getInstance().getTime();
    SimpleDateFormat Dateformat = new SimpleDateFormat("dd-MM-yyyy");
    String Today=Dateformatf.format(What_Is_Today);
    
    Toast.makeText(this,Today,Toast.LENGTH_LONG).show();
    

    at first I get time, then I declared a Simple Date Format (to get date like: 19-6-2018) then I use format to change date to string.

    0 讨论(0)
提交回复
热议问题