-1

am c# developer and in c# you can use datetime.now to get this time as example but in android studio i do not know how to do that can you help me please . not I need just hour and minute thanks

joba
  • 33
  • 1
  • 5

2 Answers2

1

You could use this example to get the current date:

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

public class GetCurrentDateTime {
    public static void main(String[] args) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        //get current date time with Date()
        Date date = new Date();
        System.out.println(dateFormat.format(date));

        //get current date time with Calendar()
        Calendar cal = Calendar.getInstance();
        System.out.println(dateFormat.format(cal.getTime()));
    }
}

Using either Date or Calendar gives the same result in this case. But if you need to set particular dates or do date arithmetic, use a Calendar. Calendars also handle localisation.

bcsb1001
  • 2,834
  • 3
  • 24
  • 35
BOUTERBIAT Oualid
  • 1,494
  • 13
  • 15
0

In Android you are programming in Java. Java Date provides the functionality you are looking for.

https://docs.oracle.com/javase/8/docs/api/java/util/Date.html

Dale Wilson
  • 9,166
  • 3
  • 34
  • 52
  • Please follow the link in my answer or type "Java Date Example" in Google. Stack overflow (and I) disapprove of "write the code for me" requests for trivial functionality. – Dale Wilson Jun 17 '16 at 21:52