当前位置: 首页 > 知识库问答 >
问题:

储存日期

邓兴为
2023-03-14

这是我的Firebase结构

我想在每个用户的第二个名字下面的“预订”下存储一天中的日期和时间,然后选择一天中的日期和时间。

这是我到目前为止用错误的方法得到的结果。它在名为“MyBookings”的单独子节点下设置日期

基本上,我所做的是单击一个显示日期和时间选择器的EditText,我需要将该日期存储在Firebase实时数据库中。

private void showDateTimeDialog(final EditText date_time_in) {
    final Calendar calendar=Calendar.getInstance();
    DatePickerDialog.OnDateSetListener dateSetListener=new DatePickerDialog.OnDateSetListener() {
        @Override
        public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
            calendar.set(Calendar.YEAR,year);
            calendar.set(Calendar.MONTH,month+1);
            calendar.set(Calendar.DAY_OF_MONTH,dayOfMonth);

            TimePickerDialog.OnTimeSetListener timeSetListener=new TimePickerDialog.OnTimeSetListener() {
                @Override
                public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                    calendar.set(Calendar.HOUR_OF_DAY,hourOfDay);
                    calendar.set(Calendar.MINUTE,minute);

                    SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yy-MM-dd HH:mm");

                    date_time_in.setText(simpleDateFormat.format(calendar.getTime()));
                    Bookings booking = new Bookings(year,month,dayOfMonth,hourOfDay,minute);
                    rootDatabaseRef.setValue(booking);
                }
            };

            new TimePickerDialog(BookingActivity.this,timeSetListener,calendar.get(Calendar.HOUR_OF_DAY),calendar.get(Calendar.MINUTE),false).show();

        }

    };

    new DatePickerDialog(BookingActivity.this,dateSetListener,calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)).show();

}

这是我的Firebase参考,我知道它是错误的,但不知道如何写才是正确的。

DatabaseReference rootDatabaseRef;
rootDatabaseRef = FirebaseDatabase.getInstance().getReference().child("MyBookings");

这是我的POJO预订课。

public int year,month,dayOfMonth,hourOfDay,minute;

public Bookings(){

}

    public Bookings(int year, int month, int dayOfMonth, int hourOfDay, int minute) {
        this.year = year;
        this.month = month;
        this.dayOfMonth = dayOfMonth;
        this.hourOfDay = hourOfDay;
        this.minute = minute;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDayOfMonth() {
        return dayOfMonth;
    }

    public void setDayOfMonth(int dayOfMonth) {
        this.dayOfMonth = dayOfMonth;
    }

    public int getHourOfDay() {
        return hourOfDay;
    }

    public void setHourOfDay(int hourOfDay) {
        this.hourOfDay = hourOfDay;
    }

    public int getMinute() {
        return minute;
    }

    public void setMinute(int minute) {
        this.minute = minute;
    }
} ```

setValue()方法的当前结果。

MyBookings
dayOfMonth: 
6
hourOfDay: 
13
minute: 
49
month: 
0
year: 
2022

如何在Firebase中的用户(仅针对当前登录的用户)下存储正确选择的日期时间?

共有1个答案

洪梓
2023-03-14

改变这个:

DatabaseReference rootDatabaseRef;
rootDatabaseRef = FirebaseDatabase.getInstance().getReference().child("MyBookings");

为此:

DatabaseReference rootDatabaseRef;
rootDatabaseRef = FirebaseDatabase.getInstance().getReference().child("MyBookings").child(username);
 类似资料:
  • 基于egg 封装公共上传类 配置上传路径 config.default.js // 上传文件类型限制 config.multipart = { fileExtensions: [ '.apk' ] // 增加对 apk 扩展名的文件支持 } // add your user config here const userConfig = { // 上传路径配置 upload_path: 'ap

  • 我有一个解析模板,它将从appsync查询中获取开始日期作为日期。但我在迪纳摩的约会是有日期时间戳的。我们如何在没有时间的情况下比较这两个日期。以下是我的解析器模板查询:

  • 问题内容: 我在使用Python和SQLite进行日期存储/检索时遇到设计问题。 我了解SQLite日期列将日期存储为ISO格式的文本(即)。因此,当我显示英国日期(例如,在网页上)时,我使用 但是,当涉及将数据写回表时,SQLite非常宽容并且非常乐意将其存储在日期字段中,但这并不理想,因为 我可能在同一列中混用了多种日期格式, SQLite的日期函数仅适用于ISO格式。 因此,在提交之前,我需

  • 问题内容: 我想在Elasticsearch中添加一个日期时间字符串时遇到问题。 该文件如下: 该文档提出了一个错误 我知道我可以在Elasticsearch中使用日期格式,但是即使阅读网站上的文档,我也不知道如何使用。 和 错了。 如何在Elasticsearch中将datetime字符串转换为日期格式? 如何将datetime字符串直接存储到Elasticsearch中? 问题答案: 你快到了

  • 日期在Oracle中是如何存储的?例如,我知道大多数系统使用Epoch时间来确定它是什么时间。通过计算距离1970年1月1日有多少秒。Oracle也这样做吗? 我问这个问题的原因是我注意到,如果在Oracle中取两个日期,然后减去它们,就会得到一个浮点数,即两个日期之间的天数。 示例 将返回类似的内容(取决于时间) 现在,Oracle是在进行转换并输出该格式,还是在存储日期时,它离某个时间段有多少

  • 我有3个节点设置 10.x.x.1-应用程序和文件拍10.x.x.2-用于解析和日志存储的机器10.x.x.3-具有集中的日志存储节点,我们需要从该节点将消息推送到弹性搜索中 10.x.x.3 logstash conf文件 是否有任何插件可以将json数据从一个logstash发送到另一个logstash服务器