Android 앱 프로젝트 용 SQLite DB가 있고 날짜 선택기에서 날짜를 저장하고 싶습니다. 가능한 한 효율적으로 해당 날짜를 문자열로 삽입 할 수 없습니다. 그래서 나는 내 날짜를 Integer 또는 Long으로 저장하려고하지만 웹에서 모든 것을 확인하고 나를 도울만큼 명확한 것은 없습니다 ...
내 코드는 다음과 같습니다.
public DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the chosen date
TextView dateView = (TextView) findViewById(R.id.newdatepicked);
// Create a Date variable/object with user chosen date
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(0);
cal.set(year, month, day, 0, 0, 0);
Date date = cal.getTime(); // CAN I USE THIS LINE?
// Format the date using style MEDIUM and FR locale
DateFormat df_date = DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
String dateDF= df_date.format(dateDF);
// Display the formatted date
dateView.setText(dateDF);
}
};
그리고 내 모든 데이터를 삽입하는 코드 :
public void SaveAlert(View v) {
String Article = tvArticle.getText().toString();
long DateEntree = calendar.getTimeInMillis(); // This line is working very well
long DateSortie = ;///////// I CANNOT FIND OUT HOW TO HANDLE THIS ...
내 문제는 DateSortie에 있습니다.
제 영어에 대해 사과하고 도움을 주셔서 감사합니다
여전히 문자열로 저장 한 다음 원하는 형식을 사용하여 검색 할 수 있습니다.
Calendar calendar = Calendar.getInstance();
/* to display time*/
SimpleDateFormat formatter = new SimpleDateFormat("hh:mm");
/* to display date in the given format */
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
/*get the date using */
Date dDate = dateFormatter.parse(yourObject.getTaskDate());
/*set the date */
calendar.setTime(dDate);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다