Tuesday, 27 August 2013

Scala String to Java Util Date Conversion

Scala String to Java Util Date Conversion

Hi the Conversion of String to Date is not possible here..
I search and use several methods but the error can not change..
here the date format is var q and convert that to formatedDate that is String
then the String convert into util date..
SearchDate is from method parameter and the value of SearchDate is "Thu
Aug 29 00:00:00 IST 2013"
var q: Date = SearchDate
var dateStr = q.toString()
var formatter: DateFormat = new SimpleDateFormat("E MMM dd HH:mm:ss Z
yyyy")
var dat = formatter.parse(dateStr)
var cal: Calendar = Calendar.getInstance()
cal.setTime(dat)
var formatedDate = cal.get(Calendar.DATE) + "-" +
(cal.get(Calendar.MONTH) + 1) + "-" + cal.get(Calendar.YEAR)
println("formatedDate : " + formatedDate)
val date = new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(dateStr)//
Error Occured Here..
the error is
Exception in thread "main" java.text.ParseException: Unparseable date:
"Thu Aug 29 00:00:00 IST 2013" at java.text.DateFormat.parse(Unknown
Source)
please share your answers ..

No comments:

Post a Comment