toofrellik toofrellik - 10 days ago 4x
Scala Question

How to get current date, month, year in scala

i need current year, month & date to 3 different variables. below code gives date time

val now = Calendar.getInstance().getTime()

Thu Sep 29 18:27:38 IST 2016

but i need in YYYY MM and DD format

val cal = Calendar.getInstance()
val date =cal.get(Calendar.DATE )
val Year =cal.get(Calendar.YEAR )
val Month1 =cal.get(Calendar.MONTH )
val Month = Month1+1

Month is added with one because month starts with zero index.