Date c = Calendar.getInstance().getTime();
System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.getDefault());
String formattedDate = df.format(c);
SimpleDateFormat timeStampFormat = new SimpleDateFormat("yyyyMMddHHmmssSS");
Date myDate = new Date();
String filename = timeStampFormat.format(myDate);
private String getDateTime() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
// Set current date into textview
tvDisplayDate.setText(new StringBuilder()
.append(month + 1).append("-") // Month is 0 based, add 1
.append(day).append("-")
.append(year).append(" Today is :" + thursday ) );
// Set current date into datepicker
dpResult.init(year, month, day, null);
public static String getDateTime() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss", Locale.getDefault());
Date date = new Date();
return simpleDateFormat.format(date);
}
Date date = new Date(); // to get the date
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy"); // getting date in this format
String formattedDate = df.format(date.getTime());
text.setText(formattedDate);
Date What_Is_Today=Calendar.getInstance().getTime();
SimpleDateFormat Dateformat = new SimpleDateFormat("dd-MM-yyyy");
String Today=Dateformatf.format(What_Is_Today);
Toast.makeText(this,Today,Toast.LENGTH_LONG).show();
Date c = Calendar.getInstance().getTime();
System.out.println("Current time => " + c);
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String formattedDate = df.format(c);
Calendar c = Calendar.getInstance();
int day = c.get(Calendar.DAY_OF_MONTH);
int month = c.get(Calendar.MONTH);
int year = c.get(Calendar.YEAR);
String date = day + "/" + (month + 1) + "/" + year;
Log.i("TAG", "--->" + date);
fun main(args: Array<String>) {
val current = LocalDateTime.now()
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")
val formatted = current.format(formatter)
println("Current Date and Time is: $formatted")}
public static String getCurrentDateAndTime(){
Date c = Calendar.getInstance().getTime();
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");
String formattedDate = simpleDateFormat.format(c);
return formattedDate;
}
val df = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.getDefault()) // pass the format pattern that you like and done.
println(df.format(Date()))
In Kotlin you can use this code : -
Simple only need to change date format to this "dd-MM-yyyy"
val d = Date()
val str: CharSequence = DateFormat.format("dd-MM-yyyy", d.getTime())
Log.e("", str.toString())
In Java You use this code: -
Date date = new Date();
CharSequence str = DateFormat.format("dd-MM-yyyy", date.getTime());
Log.e("Date", str.toString())