datetime - Date and time to milliseconds in Android -
i trying convert given date , time milliseconds. not able achieve it.
below format of date , time
02 - 07 (dd - mm) 08:50:00 (hh mm ss a)
here have tried:
string mydate = "2-05"; string mytime = "08:50:00"; string ampm = "am"; string toparse = mydate + " " + mytime+" " + ampm; try { simpledateformat formatter3 = new simpledateformat("d-m hh:mm:ss a"); // assume d-m, may refer m-d month-day instead. date date; date = formatter3.parse(toparse); long millis = date.gettime(); log.e ("date in milli",""+millis); } catch (parseexception e) { // todo auto-generated catch block e.printstacktrace(); } // need try/cat below error getting:
08-04 16:50:34.368: w/system.err(6603): java.text.parseexception: unparseable date: "2-05 08:50 am" 08-04 16:50:34.368: w/system.err(6603): @ java.text.dateformat.parse(dateformat.java:626) not sure going wrong? can me out ?
thanks!
there difference between exception you're getting , date you're supplying in code. exception says provided string 2-05 08:50 am, should providing seconds field well. should 2-05 08:50:00 am there mismatch somewhere? running old code?
as others have identified, if month 2 digits, need use mm instead of m
Comments
Post a Comment