Home > OS >  eliminate 0000 from retrieved date from FireStore and display in Text in ForEach loop
eliminate 0000 from retrieved date from FireStore and display in Text in ForEach loop

Time:07-13

How to get just date and time without 0000 from this date I retrieved from FireStore? if this is possible, can i do all process inside a Text inside ForEach?

return MyBook(bookDate: sub["bookDate"] as? String ?? "")

what i got "2022-07-11 22:31:00 0000"

what i wanted "2022-07-11 22:31:00"

CodePudding user response:

refer to this post/answer:

swiftui datepicker how to display from firebase database date and time without milliseconds?

You can use prefix for this case if it's a fixed formatted date:

date.prefix(19)
//after: "2022-07-11 22:31:00"

CodePudding user response:

It is standard date form in GMT, so suffix would be rather always the same, so you can use something like (if conversation to local zone is not needed)

"2022-07-11 22:31:00  0000"
   .components(separatedBy: " ")
   .dropLast()
   .joined(separator: " ")
  • Related