0

I am building an app which starts to run after a user given time... Now can anyone tell me how to access my Mobile's current time so that I can check it with my user given time.

Harish Rn
  • 98
  • 1
  • 9
  • 2
    Possible duplicate of [Getting the current date/time on an android device](https://stackoverflow.com/questions/33316186/getting-the-current-date-time-on-an-android-device) – Ely Jul 20 '17 at 18:13
  • Possible duplicate of [Get current time and date on Android](https://stackoverflow.com/questions/5369682/get-current-time-and-date-on-android) – Bryan Jul 20 '17 at 18:16

1 Answers1

1

You can parse whatever you want just change values inside SimpleDateFormat.

SimpleDateFormat format = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss");
System.out.println(format.format(new Date()));

If you want just time

SimpleDateFormat format = new SimpleDateFormat("hh:MM:ss");
System.out.println(format.format(new Date()));

Or you can store this datetime in string

DateFormat df = new SimpleDateFormat("HH:mm:ss");

// Get the date
Date today = Calendar.getInstance().getTime();        
// Here you can create a string 
String reportDate = df.format(today);

// For example print date or do what ever you like to do with it
System.out.println("Report Date: " + reportDate);
JakSok
  • 124
  • 4