【问题标题】:How to edit a firebase timestamp in flutter?如何在颤动中编辑firebase时间戳?
【发布时间】:2022-06-28 23:11:13
【问题描述】:

我有一个时间戳,例如 June 29, 2022 at 12:00:00 AM UTC+7。通过将此时间戳显示为字符串,我得到Timestamp(seconds=1656608400, nanoseconds=0)。但是,在将其发送到 Firestore 之前,我想将时间更改为 June 29, 2022 at 06:00:00 PM UTC+7 例如。

我目前正在使用来自syncfusion_flutter_calendar 的CalendarSelectionDetails.date 来接收选定的日期,但是时间默认为上午12 点,我还有另一个下拉菜单可以选择时间。我想将默认时间更新为下拉菜单中选择的时间。

有没有办法将其转换为字符串并编辑字符串并将其转换回时间戳,或者我应该计算我从所选时间离开的秒数并将其添加到时间戳?

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    这里我做了一个简单的函数,可以为你做到这一点

    你可以在任何你想要的地方调用它

    updateTime(){
      DateTime date = Timestamp.now().toDate();//replace the Timestamp.now with your date
      date = DateTime(date.year,date.month,date.day,6,date.minute,0,0,0);//replace the 6 with the value u want to update it to
      Timestamp newResult = Timestamp.fromDate(date);
      print("Your new time stamp is $newResult");
      return newResult;
    }
    

    【讨论】:

      猜你喜欢
      • 2022-06-11
      • 1970-01-01
      • 2020-01-20
      • 2021-02-25
      • 2020-12-03
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多