How can I get current date in Android?

前端 未结 26 1931
[愿得一人]
[愿得一人] 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:08

    try with this link of code this is absolute correct answer for all cases all over date and time. or customize date and time as per need and requirement of app.

    try with this link .try with this link

    0 讨论(0)
  • 2020-11-27 11:09
    CharSequence s  = DateFormat.getDateInstance().format("MMMM d, yyyy ");
    

    You need an instance first

    0 讨论(0)
  • 2020-11-27 11:09
     String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    

    // import Date class as java.util

    0 讨论(0)
  • 2020-11-27 11:09
    Calendar c = Calendar.getInstance();
    int day = c.get(Calendar.DAY_OF_MONTH);
    int month = c.get(Calendar.MONTH);
    int year = c.get(Calendar.YEAR);
    String date = day + "/" + (month + 1) + "/" + year;
    
    Log.i("TAG", "--->" + date);
    
    0 讨论(0)
  • 2020-11-27 11:09
    Date c = Calendar.getInstance().getTime();
    System.out.println("Current time => " + c);
    
    SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
    String formattedDate = df.format(c);
    

    This one is the best answer...

    0 讨论(0)
  • 2020-11-27 11:09
      public static String getDateTime() {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss", Locale.getDefault());
            Date date = new Date();
            return simpleDateFormat.format(date);
        }
    
    0 讨论(0)
提交回复
热议问题