Search code examples
javaandroidandroid-calendarandroid-datejava-time

Parse date from string to get milliseconds


I'm trying to get the milliseconds from an string that contains a date, but seems that I'm getting the wrong value. This is the string im trying to parse: 2015-03-01 00:00:00, I'm doing this to parse it:

 DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
 Date inputDate = dateFormat.parse(data.get(position).getValidTo());
 Log.d("--", inputDate.getDay() + " | " + inputDate.getMonth());

Solution

  • Use "MM" instead of "mm" to get month. ("mm" stands for minutes)

    And inputDate.getTime() will give the time in milliseconds.