Skip to main content

If you want to get the date and time in a specific pattern you can use the following:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()); String currentDateandTime = sdf.format(new Date()); 

Or,

Date:

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

Time:

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

If you want to get the date and time in a specific pattern you can use the following:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String currentDateandTime = sdf.format(new Date()); 

If you want to get the date and time in a specific pattern you can use the following:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()); String currentDateandTime = sdf.format(new Date()); 

Or,

Date:

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

Time:

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

If you want to get the date and time in a specific pattern you can use the following:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String curentDateandTimecurrentDateandTime = sdf.format(new Date()); 

If you want to get the date and time in a specific pattern you can use

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String curentDateandTime = sdf.format(new Date()); 

If you want to get the date and time in a specific pattern you can use the following:

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String currentDateandTime = sdf.format(new Date()); 
Source Link
Mircea Trofimciuc
  • 5.1k
  • 4
  • 19
  • 22

If you want to get the date and time in a specific pattern you can use

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss"); String curentDateandTime = sdf.format(new Date());