1

good morning,

i have this date as a String:

2016-05-20 00:00:00

now i would like to convert this string in a date format and to milliseconds.

i tried this:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");

Date convertedDate = new Date();
try {
       convertedDate = dateFormat.parse(c1.getString(c1.getColumnIndex(DatabaseHelper.COLUMN_MHD)));
} catch (ParseException e) {
      e.printStackTrace();
}

Wed Jan 20 00:00:00 MEZ 2016

but how can i convert this date now to milliseconds?

Stack108
  • 915
  • 2
  • 14
  • 35

2 Answers2

1

Use MM for month.

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

and to get Time use Date.getTime() method.

for more information take a look at Date and Time Patterns

Dhaval Patel
  • 10,119
  • 5
  • 43
  • 46
  • ahhh that was my mistake. i tried convertedDate.getTime() - but this value can not be the correct value. but with MM it works fine !. thanks :) – Stack108 May 24 '16 at 05:35
0
long timeInMilliseconds = convertedDate .getTime();
Log.d("time in millisecond",""+timeInMilliseconds );
KDeogharkar
  • 10,939
  • 7
  • 51
  • 95