Skip to main content
4 votes
0 answers
181 views

When I use a standard NumberFormatter, it honors the formattingContext of .beginningOfSentence: let formatter = NumberFormatter() formatter.numberStyle = .spellOut formatter.formattingContext = ....
Rob's user avatar
  • 441k
8 votes
1 answer
6k views

I'm trying to use the new Foundation formatters. To format a Date, I can do something like this: Date.now.formatted(.dateTime.hour().minute().second()) // 5:03:17 PM However, I'm trying to use this ...
TruMan1's user avatar
  • 36.6k
0 votes
1 answer
235 views

Why is dateRemainingText2 giving different result from dateRemainingText? Obviously dateRemainingText2 is wrong. Here's my code: import Foundation let startDate = Calendar.current.date(from: ...
user14119170's user avatar
  • 1,971
2 votes
1 answer
3k views

I have a DateComponents object that contains a month and a year and I'd like to have a formatted string from it in the style 'March 2021'. I've tried DateComponentsFormatter but none of the properties ...
ADB's user avatar
  • 729
0 votes
0 answers
293 views

I'm trying to find a way to use Swift's DateComponentsFormatter with multiple unitsStyle properties, depending on the actual component. For example, I'd like to use .abbreviated for the day property ...
neilgmacy's user avatar
  • 569
0 votes
0 answers
325 views

I want to get a relatively formatted string from TimeInterval. So I have tried following code to get custom formatted string: let ft = DateComponentsFormatter() ft.unitsStyle = .positional ft....
Alexander's user avatar
  • 163
3 votes
1 answer
384 views

In answering this question on how to create a "xxx <largest_time_units> ago" string based on comparing two dates, I wrote out a complete solution to the problem. It involves using a ...
Duncan C's user avatar
  • 132k
0 votes
2 answers
2k views

I would like to store a time of day in a simple way. For the purposes of my app, I only care about a specific time of day, like 2:30pm or 1:10am. Using a DateComponentsFormatter I can get really close....
bitops's user avatar
  • 4,360
5 votes
0 answers
445 views

I'm working on a timer in swift and came across a weird behavior for the DateComponentsFormatter when trying to format it to .zeroFormattingBehavior = .pad func timerString(duration:Int, style: ...
JacquesNorris's user avatar
0 votes
1 answer
217 views

I Want My swift code to count down to the nearest top of the hour. So if the time is 146 the user code should count down 14 minutes. Right now My code below counts down to a spefic day and time. I ...
user avatar
0 votes
2 answers
195 views

When using a DateComponentFormatter like this let formatter = DateComponentsFormatter() formatter.unitsStyle = .full formatter.includesApproximationPhrase = false formatter....
sidekickr's user avatar
  • 382
1 vote
0 answers
170 views

Show time for multiple countries with native time format. Trying to Display time of Netherland eg: 22.37 uur With Locale: nl_NL For Date: 2019-09-17 17:07:00 +0000 I have tried the code below: ...
Shashank Kaushik's user avatar
6 votes
4 answers
6k views

I am not sure what I am doing wrong, I need to find difference between two dates and extract seconds from it, below is my code. I am not getting correct seconds. There is difference of seconds. ...
Kashif Jilani's user avatar
3 votes
1 answer
987 views

So, I'm using a DateComponentsFormatter in a situation where I need to format only the nanoseconds of a given TimeInterval. The problem is that it just does not work as intended, or I'm confusing ...
Guilherme Matuella's user avatar
11 votes
4 answers
5k views

I am using the following DateComponentsFormatter in Swift: let formatter = DateComponentsFormatter() formatter.unitsStyle = .positional formatter.allowedUnits = [.hour, .minute, .second] formatter....
Evan Kaminsky's user avatar

15 30 50 per page