时间没有正确转换为unix时间

时间:2016-04-28 10:38:45

标签: java android unix time

我正在尝试根据time1和time2之间的值从数据库中检索一堆值。因此,我将time1作为参数传递(在unix时间内),然后通过提取dd-MM-yyyy并将其添加到00:01来计算time2。基本上它是,time1-(从时间1开始的12点)。出于某种原因,从我的日期格式到unix时间的转换并不正确。这是我的代码:

public Cursor getValue(long time) throws ParseException {   // Code to retrieve values steps for every 1 hour
    SQLiteDatabase sqLiteDatabase = this.getReadableDatabase();
    Cursor cu;
    String time_current = String.valueOf(time);
   Log.d("Current Time",String.valueOf(new SimpleDateFormat("yyyy-MM-dd        HH:mm", Locale.getDefault()).format(time)));

    String time_past =  String.valueOf(new SimpleDateFormat("yyyy-MM-dd ", Locale.getDefault()).format(time)) + "00:01:00.000";
    Log.d("Past time", time_past);
    Date date= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault()).parse(time_past);

    Log.d("Time passed in time format", String.valueof(date.getTime());
    cu = sqLiteDatabase.rawQuery("select * from steps_table where time_steps between " + String.valueOf(date.getTime()) + " and " + (time_current)+";", null);
    return cu;
}

"时间的日志以时间格式传递"正在显示1461781860000.而2016-04-28 12:01应该是1461801660

0 个答案:

没有答案