import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime datetime = LocalDateTime.now();
String output = formatter.format(datetime);
String date="Mar 10, 2016 6:30:00 PM";
SimpleDateFormat spf=new SimpleDateFormat("MMM dd, yyyy hh:mm:ss aaa");
Date newDate=spf.parse(date);
spf= new SimpleDateFormat("dd MMM yyyy");
date = spf.format(newDate);
System.out.println(date);
import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date = LocalDate.now();
String output = formatter.format(date);
private fun setDateFormat() {
val c = Calendar.getInstance()
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.time)
val sdfDate = SimpleDateFormat("yyyy-MMM-dd").format(c.time)
//(yyyy-MMM-dd -> 2022-Jan-14), (yyyy-MM-dd -> 2022-01-14), (yyyy-MMMM-dd -> 2022-January-14)
val sdfTime24 = SimpleDateFormat("HH:mm:ss aa").format(c.time)
val sdfTimeAm = SimpleDateFormat("hh:mm aa").format(c.time)
Log.d("Date",
"
sdf : $sdf" +
"
sdfDate : $sdfDate" +
"
sdfTime24 : $sdfTime24" +
"
sdfTimeAm : $sdfTimeAm")
/*
* Outut
* sdf : 2022-01-14 21:09:54
* sdfDate : 2022-Jan-14
* sdfTime24 : 21:09:54 pm
* sdfTimeAm : 09:09 pm
*/
}
private fun setDateFormat() {
val c = Calendar.getInstance()
val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.time)
val sdfDate = SimpleDateFormat("yyyy-MMM-dd").format(c.time)
//(yyyy-MMM-dd -> 2022-Jan-14), (yyyy-MM-dd -> 2022-01-14), (yyyy-MMMM-dd -> 2022-January-14)
val sdfTime24 = SimpleDateFormat("HH:mm:ss aa").format(c.time)
val sdfTimeAm = SimpleDateFormat("hh:mm aa").format(c.time)
Log.d("Date",
"
sdf : $sdf" +
"
sdfDate : $sdfDate" +
"
sdfTime24 : $sdfTime24" +
"
sdfTimeAm : $sdfTimeAm")
/*
* Outut
* sdf : 2022-01-14 21:09:54
* sdfDate : 2022-Jan-14
* sdfTime24 : 21:09:54 pm
* sdfTimeAm : 09:09 pm
*/
}
import java.time.*;
import java.time.format.*;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm:ss");
LocalTime time = LocalTime.now();
String output = formatter.format(time);