Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android将日期字符串转换为以毫秒为单位的时间_Android_Date_Datetime - Fatal编程技术网

android将日期字符串转换为以毫秒为单位的时间

android将日期字符串转换为以毫秒为单位的时间,android,date,datetime,Android,Date,Datetime,早上好 我将此日期作为字符串: 2016-05-20 00:00:00 现在我想将这个字符串转换为日期格式,并转换为毫秒 我试过这个: SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss"); Date convertedDate = new Date(); try { convertedDate = dateFormat.parse(c1.getString(c1.getColumnI

早上好

我将此日期作为字符串:

2016-05-20 00:00:00
现在我想将这个字符串转换为日期格式,并转换为毫秒

我试过这个:

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();
}
2016年1月20日星期三00:00:00墨西哥中部


但是现在如何将该日期转换为毫秒呢?

使用MM表示月份

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
并得到时间使用方法


有关更多信息,请查看

ahhh这是我的错误。我尝试了convertedDate.getTime()-但该值不能是正确的值。但是对于MM,它工作得很好!。谢谢:)
long timeInMilliseconds = convertedDate .getTime();
Log.d("time in millisecond",""+timeInMilliseconds );