I wrote the following code
Date d = new Date();
CharSequence s = DateFormat.format(\"MMMM d, yyyy \", d.getTime());
But is asking me para
This is the code i used:
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);
You can use following code to get a date in the format you want.
String date = String.valueOf(android.text.format.DateFormat.format("dd-MM-yyyy", new java.util.Date()));
This is the code I used:
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 String giveDate() {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
return sdf.format(cal.getTime());
}
In Kotlin
https://www.programiz.com/kotlin-programming/examples/current-date-time
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")}
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy");
String date = df.format(Calendar.getInstance().getTime());