Search code examples
iosswiftswiftuidate-formatting

How to hide Time from date string Swift


I have the string:

1980-02-17T04:00:00.000Z

I want to remove all text after "T" in:

Text(user.DOB)

How would I do this?

Thank you


Solution

  • While not particularly sophisticated, you could simply go for

    Text(user.DOB.prefix(10))
    

    It lets you keep MongoDB's format for elsewhere in your app if you end up needing it.