我想设置闹钟。但我的日期和时间都存储在db中。当我得到这些时,它们都是字符串。当我得到日期和时间时,看起来像这样:
AM4 / 11/2015 10:33
请告诉我如何以毫秒为单位转换此内容。我是新来的,请忽略发布的问题。
for (int i = 0; i < names.size(); i++) {
ShoppingListItem item = new ShoppingListItem();
item.setCategory(names.get(i).getCategory());
item.setTitleName(names.get(i).getTitle());
item.setTimeVal(names.get(i).getTime());
item.setCalender(names.get(i).getCalendar());
item.setAddres(names.get(i).getAddress());
item.setDb_row_id(names.get(i).getDb_row_id());
//item.setColorImage(names);
mAdapter.addItem(item);
String s = names.get(i).getTime() + names.get(i).getCalendar();
System.out.println("GetTime"+s);
答案 0 :(得分:2)
您需要解析格式化的字符串日期。
试试这个:
SimpleDateFormat sdformat = new SimpleDateFormat("hh:mm aaMM/dd/yyyy");
Date date = sdformat.parse(your-string-date);
long milliseconds = date.getTime(); //<--here gets the milliseconds
答案 1 :(得分:0)
请尝试以下代码
Calendar rightNow = Calendar.getInstance();
// offset to add since we're not UTC
long offset = rightNow.get(Calendar.ZONE_OFFSET) +
rightNow.get(Calendar.DST_OFFSET);
long sinceMidnight = (rightNow.getTimeInMillis() + offset) %
(24 * 60 * 60 * 1000);
System.out.println(sinceMidnight + " milliseconds since midnight")