I want to get the current date so I used:
Calendar.getInstance().getTime() But as it .getTime() it is returning:
Fri Jul 11 15:07:03 IST 2014 I want only date in any format but without the time.
scala> java.time.LocalDate.now res4: java.time.LocalDate = 2014-07-11 error: object time is not a member of package javaSince Java 8, you can also use LocalDate class:
println(java.time.LocalDate.now) OR
java.time.LocalDate.now.toString scala> java.time.LocalDate.now.toString /n res2: String = 2018-11-14val dateFormatter = new SimpleDateFormat("dd/MM/yyyy hh:mm aa") var submittedDateConvert = new Date() submittedAt = dateFormatter.format(submittedDateConvert) if someone needs the date in a format so that to be able to add to PostgreSQL here we go:
import java.util.Calendar val calendar = Calendar.getInstance val now = new Timestamp(calendar.getTime.getTime) or in one line:
val now = new Timestamp(java.util.Calendar.getInstance.getTime.getTime)