I have a timestamp for example June 29, 2022 at 12:00:00 AM UTC 7
. By displaying this timestamp into a string I get Timestamp(seconds=1656608400, nanoseconds=0)
. However before sending this to firestore, I'd like to change the time into June 29, 2022 at 06:00:00 PM UTC 7
for example.
I am currently using CalendarSelectionDetails.date
from syncfusion_flutter_calendar in order to receive the selected date, however the time is defaulted to 12AM, and I have another drop down menu to select the time. I'd like to update the default time to the time selected in the drop down menu.
Is there a way to convert it to a string and edit the string and convert it back to timestamp, or should I calculate how many seconds I'm off from the selected time and add it to timestamp?
CodePudding user response:
here i have made a simple function that can do that for you
you can call it where ever you want
updateTime(DateTime date){
DateTime inputDate = 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(inputDate);
print("Your new time stamp is $newResult");
return newResult;
}
here is how you can use it
updateTime(Timestamp.now().toDate());