get system time in android code example

Example 1: android get date

String currentDate = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault()).format(new Date());

Example 2: android studio get time

String currentTime = new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(new Date());

Example 3: code to get date and time in android

String dateStr = "04/05/2010"; 

SimpleDateFormat curFormater = new SimpleDateFormat("dd/MM/yyyy"); 
Date dateObj = curFormater.parse(dateStr); 
SimpleDateFormat postFormater = new SimpleDateFormat("MMMM dd, yyyy"); 

String newDateStr = postFormater.format(dateObj);

Example 4: code to get date and time in android

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

Tags:

Java Example