Ich habe versucht,: < /p>
Code: Select all
Text(startDate, style: .relative)
< /code>
Es gibt auch: < /p>
Text(TimeDataSource.currentDate, format:
.stopwatch(startingAt: startDate, showsHours: true,
maxFieldCount: 1, maxPrecision: .seconds(1)))
Code: Select all
extension FormatStyle where Self == SystemFormatStyle.CustomStopwatchStyle {
public static func customStopWatch(date: Date) -> SystemFormatStyle.CustomStopwatchStyle {
return SystemFormatStyle.CustomStopwatchStyle(d: date)
}
}
extension SystemFormatStyle {
public struct CustomStopwatchStyle: Sendable, FormatStyle {
public typealias FormatInput = Date
public typealias FormatOutput = String
var d: Date
init(d: Date) {
self.d = d
}
public func format(_ value: Date) -> String {
return formattedDate(date: value)
}
}
Text(TimeDataSource.currentDate, format: .customStopWatch(date: startDate))