0

I have a SQLite DB for my Android app project and I would like to save a date from a Date Picker. TO be as efficient as possible, I cannot insert that date as a String. So I'm trying to save my date as an Integer or a Long but I check all around the web and nothing clear enough to help me...

Here is my code:

   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);

    }
};

And my code to insert all my data:

  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 ...

My issue is with DateSortie.

Please let me apologize for my English and thanks a lot for your help

Meidi K
  • 3
  • 1
  • 2

1 Answers1

3

you can still store it as string and then retrieve them using the format you want for example

  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);
Anirudh Goud
  • 346
  • 2
  • 11