0

I'm new to Android Studio and new to the Firebase database as well. I have created an app but I don't know how to store date and time. Can you help me guys?
Here below is my code:

public class TimeBookActivity extends AppCompatActivity implements View.OnClickListener, DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener {

    private FirebaseAuth auth;
    private DatabaseReference databaseReference;
     Button bnt_picDate_picDate;
     TextView textView3;
    int time, day, month, year, hour, minute, a;
    int timeFinal, dayFinal, monthFinal,yearFinal, hourFinal, minuteFinal;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_book);

        auth = FirebaseAuth.getInstance();
        if (auth.getCurrentUser()== null){
            startActivity(new Intent(TimeBookActivity.this, LoginActivity.class));
        }

        databaseReference = FirebaseDatabase.getInstance().getReference();
        textView3 = (TextView) findViewById(R.id.textView3);
        bnt_picDate_picDate = (Button) findViewById(R.id.bnt_picDate_picDate);

        FirebaseUser user = auth.getCurrentUser();

        bnt_picDate_picDate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v == bnt_picDate_picDate){

                    Calendar c = Calendar.getInstance();
                    year = c.get(Calendar.YEAR);
                    month = c.get(Calendar.MONTH);
                    day = c.get(Calendar.DAY_OF_MONTH);

                    DatePickerDialog datePickerDialog = new DatePickerDialog(TimeBookActivity.this, TimeBookActivity.this, year, month, day);
                    datePickerDialog.show();

                }


            }
        });


    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void onDateSet(DatePicker view, int i, int i1, int i2) {
        String[] months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
        yearFinal = i;
        monthFinal = i1 + 1;
        dayFinal = i2;
        String monthS = months[i1];

        Calendar c = Calendar.getInstance();
        hour = c.get(Calendar.HOUR_OF_DAY);
        minute = c.get(Calendar.MINUTE);
        year = c.get(Calendar.YEAR);
        month = c.get(Calendar.MONTH);

        textView3.setText("Year: "+yearFinal+ "\n" +
                "Month: "+monthS+ "\n" +
                "Day: "+dayFinal+ "\n" +
                "Hour: "+hourFinal+ "\n" +
                "Minute: "+minuteFinal+ "\n" +
                "\n" +"Congratulation You are Booked!");

        TimePickerDialog timePickerDialog = new TimePickerDialog(TimeBookActivity.this,TimeBookActivity.this,hour,minute, DateFormat.is24HourFormat(TimeBookActivity.this));

        DatePickerDialog datePickerDialog = new DatePickerDialog(TimeBookActivity.this, TimeBookActivity.this, year, month, day);

    }

    @Override
    public void onTimeSet(TimePicker view, int i, int i1) {
        hourFinal = i;
        minuteFinal = i1;


    }
}
Dee21
  • 31
  • 1
  • 3
  • 1
    Welcome to Stack Overflow! I've edited your question, putting your code in `code markdown`. You could further improve the question, by explaining a bit more. You can [edit] the post to tell us what you've tried, what you expected to happen, and what happened instead. Or, if you were unable to find the right calls, tell us what you _did_ find when searching the documentation. This helps us to better understand the problems you're experiencing, and thus helps us to help you. Good luck! – S.L. Barth is on codidact.com Mar 30 '17 at 06:44

1 Answers1

0
Calendar c = Calendar.getInstance();
            c.set(Syear, Smonth, Sday, Shours, Sminute);
            long startDate = c.getTimeInMillis();

where Syear, Smonth, Sday, Shours, Sminute you can get it from your OnDateSet and OnTimeSet now you can put Datetime to your FireBase as long

Elsunhoty
  • 1,609
  • 14
  • 27