score:35
You may use formatting:
val format = new SimpleDateFormat("d-M-y")
println(format.format(Calendar.getInstance().getTime()))
score:1
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)
score:4
In case if you want to format the date in your way.
println(DateTimeFormatter.ofPattern("dd-MM-YYYY").format(java.time.LocalDate.now))
score:5
You need to use SimpleDate formate method. You can specify which formate you want.
SimpleDateFormat formatter = new SimpleDateFormat("dd/mm/yy");
String dateSelected = formatter.format(new Date());
score:6
val dateFormatter = new SimpleDateFormat("dd/MM/yyyy hh:mm aa")
var submittedDateConvert = new Date()
submittedAt = dateFormatter.format(submittedDateConvert)
score:18
Since Java 8, you can also use LocalDate
class:
println(java.time.LocalDate.now)
OR
java.time.LocalDate.now.toString
score:79
scala> java.time.LocalDate.now
res4: java.time.LocalDate = 2014-07-11
Source: stackoverflow.com
Related Query
- How to get the current date without time in scala
- How to get the first date and last date using current month and year on scala
- How to get current timestamp in Scala as a string without spaces?
- get Current Date in Scala without java class
- Scala: How do I get the current time in RFC 822 / 1123 format
- How to get the current local time or system time in spark-scala dataframe?
- How to get the current and next element of List of list of options in scala
- How to get the name of a nested object in Scala without its package name and without $?
- How to get the index of the current char while iterating over a string in scala
- How to get current day of the week and used it in scala template in Play framework
- How do I write a script in Scala that converts the current time to the number of seconds since midnight?
- How to get current time in Scala in timestamp/datetime format so that it can be stored in PG table
- How to get the last date of a particular month with JodaTime?
- How do I get the Scala version from within Scala itself?
- How the get the classOf for a scala object type
- In Scala, how to get a slice of a list from nth element to the end of the list without knowing the length?
- How to get around the Scala case class limit of 22 fields?
- How can I get the current SparkSession in any place of the codes?
- How to get the option to create a new Scala Worksheet in IntelliJ?
- How to get the line separator of current os easily in Scala?
- How to get Scala imports working in IntelliJ IDEA with the Play framework?
- How to get the name of a case class field as a string/symbol at compile time using shapeless?
- How to get the current (working) directory in Scala?
- How can I syntax check a Scala script without executing the script and generating any class files?
- How to correctly get current loop count from a Iterator in scala
- How can I get the actual object referred to by Scala 2.10 reflection?
- How do I get IntelliJ to display the Scala compilation deprecation warnings
- How do I use Scala dispatch to get the URL returned in a 301 redirect?
- How to modify previous line in REPL - scala to modify the typing errors to save time compare to entering each line using up/down arrows
- Convert current time in milliseconds to Date Time format in Scala
More Query from same tag
- Read XML with attribute names in Scala
- how to specify a custom stylesheet in scalate ssp
- What is the efficient way to create Spark DataFrame in Scala with array type columns from another DataFrame that does not have an array column?
- Json Validation with PlayFramework in Scala
- Gradle build failed with Kotlin, Scala and Java
- Sbt: compile using Java 6 and run using Java 7
- How to use one url for several actions based on profile information?
- Get rid of Option [T] when get values from Map[T, T]
- scio type safe BigQuery classes - annotation issue
- Scala Named Arguments
- scala pattern matching in actor class
- abandon calling `get` on Option and generate compile error
- How to Let JavaScript Apps Loaded from Any Domain Access All Public Assets When CORS Is Enabled
- How to extract a previous and next line sentence in spark?
- Possible to code generic return types in Scala similar to C++ templates?
- Scala mock polymorphic methods with implicit type tag
- Class akka.actor.TypedActor$MethodCall can not access a member of class JobManager with modifiers "public abstract"
- How to convert java stream collect to scala
- Using Scala 2.10 reflection how can I list the values of Enumeration?
- (run-main-0) java.lang.NoSuchMethodError
- Changing clocking in RocketSubsystemModuleImp from System.scala
- Idiomatic Scala for nested loop
- Not able to read conf file in spark scala
- Why awakeEvery was removed from scalaz-stream
- Spark Streaming filter condition inside foreach - NullPointerException
- Write function with type parameter
- How to deploying Scala HTTP4S app to Heroku?
- How use guave cache loader in F polymorphic code
- How to get a logger on my own class name using Play2/scala?
- Computation with time limit