Android Cursor Read getDate(Cursor cursor, String columnName)

Here you can find the source of getDate(Cursor cursor, String columnName)

Description

get Date

License

Apache License

Declaration

public static Date getDate(Cursor cursor, String columnName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import android.database.Cursor;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import java.util.Locale;

public class Main {
    public static Date getDate(Cursor cursor, String columnName) {
        String dateString = cursor.getString(cursor
                .getColumnIndex(columnName));
        if (dateString == null) {
            return null;
        }//  w  w w  . j  a  v  a 2  s  .co m
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",
                Locale.ENGLISH);
        Date date = null;
        try {
            date = format.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }
}

Related

  1. getPhotoPathByLocalUri(Context context, Intent data)
  2. getIntFromCursor(Cursor cursor, String columnName)
  3. getStringFromCursor(Cursor cursor, String columnName)
  4. getPositionById(Cursor cursor, long theTargetId)
  5. newClosedCursor()