Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the current date without time in scala

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.

like image 654
Govind Singh Avatar asked Jul 11 '14 09:07

Govind Singh


People also ask

How do I get current date in Scala spark?

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.

How do you use dates in Scala?

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.

How do I change the date format in Scala?

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.


2 Answers

scala> java.time.LocalDate.now res4: java.time.LocalDate = 2014-07-11 
like image 88
Knut Arne Vedaa Avatar answered Oct 12 '22 02:10

Knut Arne Vedaa


You may use formatting:

val format = new SimpleDateFormat("d-M-y") println(format.format(Calendar.getInstance().getTime())) 
like image 20
artie Avatar answered Oct 12 '22 04:10

artie