# New Date.FormatStyle: Anyway to do 24 hour?

**URL:** <https://forums.swift.org/t/new-date-formatstyle-anyway-to-do-24-hour/52994>\
**Category:** Using Swift\
**Created:** [October 23, 2021, 1:07am UTC](https://forums.swift.org/t/new-date-formatstyle-anyway-to-do-24-hour/52994 "2021-10-23T01:07:41Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![young](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/young/32/7878_2.png) [@young](https://forums.swift.org/u/young)\
**Post date:** [October 26, 2021, 4:10pm UTC](https://forums.swift.org/t/new-date-formatstyle-anyway-to-do-24-hour/52994/11 "2021-10-26T16:10:34Z")

</div>

> [@tera](#):
>
> that's quite non obvious... have a formatter/format parameter which is ... ignored?

That's how SwiftUI view that deal with `Date` value work: `DatePicker` and `Text<Subject>(Subject, formatter: Formatter)`.

The problem is the new `Text<F>(F.FormatInput, format: F)` only use `Locale` from environment, but not for `TimeZone` and `Calendar`. I think it's a bug I reported FB9217356.

Look at this example, the second `Text` use the Locale, Timezone and Calendar from the environment, the first Text only use Locale from environment:

```swift
    static let when = Date(timeIntervalSince1970: 15*3600)
    static let locale = Locale(identifier: "en_US_POSIX")
    static let timeZone = TimeZone(identifier: "UTC")!

    static let localeChina = Locale(identifier: "zh_Hans_CN")
    static let calendar = Calendar(identifier: .chinese)

    static let dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .long
        formatter.timeStyle = .long
        return formatter
    }()

    var body: some View {
        // this one only use locale from environment, not timezone and calendar. it's a bug
        Text(Self.when, format: Date.FormatStyle.dateTime.locale(Self.locale))
            .environment(\.locale, Self.localeChina) // it's using this locale, not the one set above
            .environment(\.timeZone, Self.timeZone) // but it's not using this, still at system default
            .environment(\.calendar, Self.calendar) // and not this
        // this surely has to show "15:00", right?
        // nope... "1/1/1970, 4:00 PM"
        // same with en_US. slightly better but still wrong with en_UK (16:00)

        // this one use locale, timezone and calendar from environment:
        Text(Self.when, formatter: Self.dateFormatter)
            .environment(\.locale, Self.localeChina) // it's using this
            .environment(\.timeZone, Self.timeZone) // and this
            .environment(\.calendar, Self.calendar) // and this
    }

```

---

_[View the full topic](https://forums.swift.org/t/new-date-formatstyle-anyway-to-do-24-hour/52994)._
