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.
Spark SQL provides <em>current_date</em>() and <em>current_timestamp</em>() functions which returns the current system date without timestamp and current system data with timestamp respectively, Let's see how to get these with Scala and Pyspark examples.
In scala we do not have any date-time library or function available, we can use java data time, calendar, Date library to deal with dates in Scala. By using these functions, we can convert our date to a string and vice versa, also we can format our date.
You'll create a SimpleDateFormat class passing in the pattern to represent your date format, parse it, then you can convert each one to milliseconds to find the min and max. You don't need to format() multiple dates into a common String format in order to compare them and find min or max.
scala> java.time.LocalDate.now res4: java.time.LocalDate = 2014-07-11
You may use formatting:
val format = new SimpleDateFormat("d-M-y") println(format.format(Calendar.getInstance().getTime()))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With