我用了
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
String time = formatter.format(new Date());
Run Code Online (Sandbox Code Playgroud)
得到时间(12.03.2012,17:31),现在我想将这个时间转换为毫秒,因为我有一个带有几个日期和文本的文件,我想以毫秒转换日期,以便我不能添加收件箱中的文字使用
ContentValues values = new ContentValues();
values.put("address", "123");
values.put("body", "tekst");
values.put("read", 1);
values.put("date", HERE I MUST PUT A DATE IN MILLISECONDS);
context.getContentResolver().insert(Uri.parse("content://sms/inbox"), values);
Run Code Online (Sandbox Code Playgroud)
因为我必须花费时间以毫秒为单位,我必须转换时间,有谁知道如何?
Ale*_*s G 25
最简单的方法是将Date类型转换为毫秒:
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm");
formatter.setLenient(false);
Date curDate = new Date();
long curMillis = curDate.getTime();
String curTime = formatter.format(curDate);
String oldTime = "05.01.2011, 12:45";
Date oldDate = formatter.parse(oldTime);
long oldMillis = oldDate.getTime();
Run Code Online (Sandbox Code Playgroud)