Get local time

 from https://stackoverflow.com/questions/16089586/android-sqlite-save-and-retrieve-utc-and-convert-to-local?rq=1



Calendar sourceCalendar = Calendar.getInstance();
sourceCalendar.setTimeZone(TimeZone.getTimeZone("Asia/Taipei"));
//SimpleDateFormat sdf = new SimpleDateFormat();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("Asia/Taipei"));
//String outputDateString = sdf.format(sourceCalendar.getTime());
contentValues.put("GetTime", sdf.format(sourceCalendar.getTime()));

留言

熱門文章