Saving and retrieving date in Firebase

后端 未结 5 1342
失恋的感觉
失恋的感觉 2020-12-09 04:12

I have a model with the following structure

public class OfferModel {
    private String mImageUrl;
    private String mOfferCode;
    private String mOffe         


        
5条回答
  •  旧巷少年郎
    2020-12-09 04:36

    Use ISO 8601 date format:

    SimpleDateFormat ISO_8601_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:sss'Z'");
    
    String now = ISO_8601_FORMAT.format(new Date());
    

    Representing Date as a String has two greater advantages:

    • It is human readable ("2018-03-30T13:18:39.516Z" vs 1522415925281)
    • At the browser side, you can simply invokes new Date("2018-03-30T13:18:39.516Z")

    This is quite useful if you have Android and browsers both consuming Firebase data.

提交回复
热议问题