toofrellik toofrellik - 1 year ago 252
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

Answer Source
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download