how to get system date in android

‮.www‬lautturi.com
how to get system date in android
import java.text.SimpleDateFormat;

// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
SimpleDateFormat sdf = new SimpleDateFormat("ddMMyyyy_HHmmss", Locale.getDefault());
String currentDateandTime = sdf.format(new Date());
System.out.println("currentDateandTime:" + currentDateandTime);

output:

currentDateandTime: 03112020_073544

one line code:

/**
 * @author lautturi.com
 * Java example: get current date in android
 */

import java.util.*;
import java.text.SimpleDateFormat;
import java.time.*;

public class Lautturi {

	
	public static void main(String[] args) {

		String date = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(new Date());
		System.out.println("currentDate:" + date);
        
	}

}
Created Time:2017-08-31 05:39:48  Author:lautturi