如何将Firebase子名称转换为日期和时间

时间:2018-03-01 20:06:29

标签: date firebase datetime firebase-realtime-database datepicker

我有一个基本应用程序,其中包含RecyclerView,用于从Firebase数据库获取数据,如下所示:

enter image description here

我希望将20170108_100转换为数据和时间格式(08/01/2017 10:00),然后将其与实际日期进行比较。

我计划有一些IF条件,以便按日期和时间对数据库进行排序,我需要这样的事情:

if (20170108_100 < CurrentDate&Time) then doSomething else doSomethingElse

有没有办法可以做到这一点?

到目前为止,我有这个代码读取该数据库:

public class Hotarari extends Fragment {

  View v;
  ProgressDialog progress;
  private FirebaseRecyclerAdapter < Variabile_primarie, ContactViewHolder > cc;
  private RecyclerView mContactRV;
  private DatabaseReference mPostRef;


  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
    v = inflater.inflate(R.layout.fragment_hotarari, container, false);
    return v;
  }

  @Override
  public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    this.v = view;
    initialiseScreen();
  }

  private void initialiseScreen() {
    mContactRV = (RecyclerView) v.findViewById(R.id.contact_recyclerview);
    mContactRV.setLayoutManager(new LinearLayoutManager(getContext()));
    mPostRef = FirebaseDatabase.getInstance().getReference("-DeciziiPrimari");
    setupAdaptater();
    mContactRV.setAdapter(cc);
  }

  private void setupAdaptater() {
    cc = new FirebaseRecyclerAdapter < Variabile_primarie, ContactViewHolder > (
      Variabile_primarie.class,
      R.layout.item_hotarari,
      ContactViewHolder.class,
      mPostRef
    ) {
      @Override
      protected void populateViewHolder(ContactViewHolder viewHolder, final Variabile_primarie model, int position) {
        viewHolder.setData(model.getData());
        viewHolder.setNumar(model.getNumar());
        viewHolder.setHotarare(model.getHotarare());
      }
    };
  }

  public static class ContactViewHolder extends RecyclerView.ViewHolder {
    private TextView tv_hotarare;
    private TextView tv_data;
    private TextView tv_numar;

    public ContactViewHolder(View itemView) {
      super(itemView);
      tv_hotarare = (TextView) itemView.findViewById(R.id.continut_hotarare);
      tv_data = (TextView) itemView.findViewById(R.id.data_hotarare);
      tv_numar = (TextView) itemView.findViewById(R.id.numar_hotarare);
    }
    void setHotarare(String hotarare) {
      tv_hotarare.setText(String.valueOf(hotarare));
    }

    public void setData(String data) {
      tv_data.setText(String.valueOf(data));
    }

    void setNumar(String numar) {
      tv_numar.setText(String.valueOf(numar));
    }
  }
}

0 个答案:

没有答案