I have a date variable
var date: Date = new Date()
then I have converted this date to String:
var dateStr = date.toString()
now I need to convert back this String to date. I have tried both:
1:
var stringToDate: Date = date2Str.asInstanceOf[Date]
and 2:
stringToDate: Date = new SimpleDateFormat("dd.MM.yyyy").parse(dateStr);
But in both case I got the error:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
Convert text dates by using the DATEVALUE function Select a blank cell and verify that its number format is General. Click the cell that contains the text-formatted date that you want to convert. Press ENTER, and the DATEVALUE function returns the serial number of the date that is represented by the text date.
Convert from human-readable date to epochlong epoch = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse("01/01/1970 01:00:00").getTime() / 1000; Timestamp in seconds, remove '/1000' for milliseconds. date +%s -d"Jan 1, 1980 00:00:01" Replace '-d' with '-ud' to input in GMT/UTC time.
This year, the month of Sawan will begin from 25 July 2021. Devotees of Lord Shiva consider this month very auspicious and observe it with full enthusiasm and devotion. Sawan, the fifth month of the Hindu calendar, falls during the month of July-August.
Year Gregorian = Year Muslim × 0.97 + 622. If you want to convert a Gregorian date to a Muslim date, you need to subtract 622 from the original year and then multiply by 1.03: Year Muslim = (Year Gregorian– 622) × 1.03.
I see a couple of problems in your code, but this works fine:
scala> val format = new java.text.SimpleDateFormat("dd-MM-yyyy") format: java.text.SimpleDateFormat = java.text.SimpleDateFormat@9586200 scala> format.format(new java.util.Date()) res4: java.lang.String = 21-03-2011 scala> format.parse("21-03-2011") res5: java.util.Date = Mon Mar 21 00:00:00 CET 2011
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