티스토리 뷰
2010년 10월 기준.
private SQLiteDatabase db;
private final static String DB_NAME = "TapSonic.db";
private final static int DB_MODE = Context.MODE_PRIVATE;
private final static String T_NAME = "add";
public void openDB(Context c)
{
db = c.openOrCreateDatabase(DB_NAME, DB_MODE, null);
}
public void executeDB(String sql)
{
sql = "SELECT id, name, add FROM ";
sql += T_NAME;
sql += " WHERE id = 'medits'";
Log.e("executeDB", sql);
try {
Cursor cur = db.rawQuery(sql, null);
cur.moveToFirst();
if (cur.getCount() > 0) {
//tv.setText(cur.getString(1));
//tv.setText(cur.getString(cur.getColumnIndex("address")));
} else {
Log.e("executeDB", "Data is not exist");
}
} catch (SQLException e) {
Log.e("executeDB Error", e.toString());
}
}
public ArrayListgetListData(String sql) {
ArrayListarrayList;
arrayList = new ArrayList();
try {
Cursor c = db.rawQuery(sql, null);
c.moveToFirst();
if (c.getCount() > 0) {
int index;
String name;
for (int i=0;i
name = c.getColumnName(i);
index = c.getColumnIndex(name);
arrayList.add(Integer.toString(index)+","+name);
}
}
} catch (Exception e) {
}
return arrayList;
}
// 타입 처리
date('now') : 현재 입력
datetime('now')
android.util or android.text.util 을 참고
입력은 "yyyy-MM-dd HH:mm:ss" 포맷 문자열로 해야됨
String dateTime = row.getString(row.getColumnIndexOrThrow(COLUMN_INDEX));
DateFormat iso8601Format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
date = iso8601Format.parse(dateTime);
} catch (ParseException e) {
Log.e(TAG, "Parsing ISO8601 datetime failed", e);
}
long when = date.getTime();
int flags = 0;
flags |= android.text.format.DateUtils.FORMAT_SHOW_TIME;
flags |= android.text.format.DateUtils.FORMAT_SHOW_DATE;
flags |= android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
flags |= android.text.format.DateUtils.FORMAT_SHOW_YEAR;
String finalDateTime = android.text.format.DateUtils.formatDateTime(context,
when + TimeZone.getDefault().getOffset(when), flags);
SimpleDateFormat sdf =
new SimpleDateFormat(getResources().getString(R.string.DATE_FORMAT_ISO8601));
Date date = new Date(); //or new Date(long millis);
date.setTime(millis); //for now, use: System.currentTimeMillis()
int millis = date.getTime();
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT); //or
MEDIUM..
formattedDate = df.format(date);
date = df.parse(formattedDate);
## Date 형 변환 순서 정리
TIMESTAMP -> Cursor.getInt()
-> Date.setTime(t*1000) -> DateFormat.format()
'Study' 카테고리의 다른 글
Android(안드로이드) SQLite DB 확인 (0) | 2023.03.24 |
---|---|
CentOS(센트오에스) 7 php(피에이치피) 세팅 (0) | 2023.03.22 |
Adobe(어도비) Flash(플래시) 단축키 (0) | 2023.02.28 |
Adobe(어도비) Flash(플래시) EscapeEUCJP (0) | 2023.02.28 |
Web Browser(웹 브라우저) FTP(에프티피) 접속 (0) | 2023.02.25 |