DEV Community

Cover image for Using DateTemplates in SwiftUI for custom date formatting
Eneko Alonso
Eneko Alonso

Posted on

1

Using DateTemplates in SwiftUI for custom date formatting

DateTemplates is a library that provides a simple way to generate date formatting templates that can be used to format dates in all Apple platforms and Linux. With a declarative Swift syntax that's easy to read and natural to write, DateTemplate works seamlessly with DateFormatter.

In SwiftUI, we can use it to easily format dates inline with out view code:

Text(
    DateTemplate()
        .dayOfWeek(.full)
        .month(.abbreviated)
        .day()
        .time()
        .localizedString(from: entry.timestamp)
)

Using DateTemplate in SwiftUI

Visit https://github.com/eneko/DateTemplates for more examples and documentation.

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay