get Time By Database Cursor - Android Database

Android examples for Database:Cursor Get

Description

get Time By Database Cursor

Demo Code


import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public class Main{
    public static String getTimeByCursor(Cursor c, int index) {
        try {//from  w  w w  .jav  a 2 s  .  c  om
            String timestamp = c.getString(index);
            return DBUtil.getTimeFromString(timestamp);
        } catch (Exception e) {
            return null;
        }
    }
    public static String getTimeFromString(String timestamp) {
        try {
            DateFormat dateFormat = DateFormat.getDateTimeInstance(
                    DateFormat.SHORT, DateFormat.SHORT);
            String timeString = dateFormat.format(new Date(Long
                    .parseLong(timestamp)));
            return timeString;
        } catch (Exception e) {
            return null;
        }
    }
}

Related Tutorials