如何在java中解析来自SQLite数据库的数据

如何在java中解析来自SQLite数据库的数据,java,android,date,datetime,Java,Android,Date,Datetime,我试图解析来自db的日期(2014-06-1116:58:12.903),如下所示 DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("tr-TR")); String tarih = cursor.getString(cursor.getColumnIndex("Created"); tarih = tarih.replace("T", " "); Object.Created = da

我试图解析来自db的日期(2014-06-1116:58:12.903),如下所示

DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("tr-TR"));
String tarih = cursor.getString(cursor.getColumnIndex("Created");
tarih = tarih.replace("T", " ");
Object.Created = dateFormat.parse(tarih);
下面的代码还返回“Fri Dec 04 16:58:12 EET 16”

此方法返回的日期类似于“Wed Jun 11 16:58:12 EEST 2014”


如何获取日期,如dd-MM-YYYY>11-06-2014

//在方法中添加以下代码行

SimpleDateFormat fmtOut = new SimpleDateFormat("dd-MM-yyyy");
return fmtOut.format(tarih);
请注意这个月的因素。(获取今天的日期)

//年份值中的问题可能是因为从数据库检索的数据

   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("tr-TR"));
    String tarih ="";
    try
    {
    tarih = dateFormat.parse(cursor.getString(cursor.getColumnIndex("Created"));
    }catch (ParseException e) {
    tarih = "";
    }
log.w("Data from database",tarih);
    tarih = tarih.replace("T", " ");
    Object.Created = tarih;

谢谢这似乎很有效,但我没有得到一件事,它解析为“2014-06-11 00:00:00”,比如“Fri-Dec 04 00:00:00 EET 16”,你认为这一年有什么问题吗?原因是-月从0开始到11。根据SimpleDateFormat类,数字11代表12月份。谢谢,但在解析日期中,是04和16,是2014年吗?这部分我没有get@BahadirGul,尝试使用上述代码,如果您仍然面临此问题,请提及从DB获得的日志值
final Calendar c = Calendar.getInstance();

 int year = c.get(Calendar.YEAR);
 int month = c.get(Calendar.MONTH)+1; // INCREMENT MONTH VALUE BY 1 (we get 0 for january and 11 for december)
 month_name = map_instance.findMonthName(month+"");
 int day = c.get(Calendar.DAY_OF_MONTH);
   DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", new Locale("tr-TR"));
    String tarih ="";
    try
    {
    tarih = dateFormat.parse(cursor.getString(cursor.getColumnIndex("Created"));
    }catch (ParseException e) {
    tarih = "";
    }
log.w("Data from database",tarih);
    tarih = tarih.replace("T", " ");
    Object.Created = tarih;