Unparseable date error in Java -
i want convert system date yyyy-mm-dd
format. there similar questions in so. found need parse date in input format , convert output format. stuck @ first stage itself. not able parse system date such (sat apr 25 14:44:15 ist 2015
).
here mwe:
import java.util.*; import java.text.*; public class test { public static void main(string[] args) { try { date date = new date(); simpledateformat dateformat = new simpledateformat("eee mm dd hh:mm:ss aaa yyyy"); date = dateformat.parse(date.tostring()); system.out.println(date); } catch(exception e) { system.out.println(e.getmessage()); } } }
i exception :
unparseable date: "sat apr 25 14:53:33 ist 2015"
date
object can converted string of date format. string can converted date come in standard date format's cant in 1 want..
if want format system date yyyy-mm-dd format use:
date date = new date(); simpledateformat dateformater = new simpledateformat("yyyy-mm-dd"); string date1 = dateformater.format(date);
as specified in comment want subtract sql date current date convert sql date normal date format.
this:
string date = date; simpledateformat dateformat = new simpledateformat("yyyy-mm-dd"); date date1 = dateformat.parse(date); date currentdate = new date();
then use calender objects:
calendar calendar = calendar.getinstance(); calendar.settime(date1); calendar calendar2 = calendar.getinstance(); calendar2.settime(currentdate); long difference = (calendar2.gettimeinmillis() - calendar .gettimeinmillis()) / 60000;
this give difference between 2 dates in minutes.
Comments
Post a Comment