Questions tagged [swiftdate]

SwiftDate is a 3rd party Swift library to make it easier to work with Dates and TimeZones.

Main features of SwiftDate:

  • Simple math operations with dates! Example: aDate + 2.weeks + 1.hour or (1.year - 2.hours + 16.minutes).fromNow()
  • Easy conversions to and from timezone, locale and calendar. Use the helper class DateInRegion and perform conversions with components and operations!
  • Compare dates with math operators <,>,==,<=,>=. For example, you can do aDate1 >= aDate2 or aDate1.isIn(anotherDate,.day)
  • Easily work with time components. E.g. aDateInRegion.day or hour, minutes etc. expressed in your favourite timezone!
  • Easy and optimized way to get and transform a date from and to strings: supports both colloquial (human readable) and fixed formats (ISO8601, AltRSS, RSS, Extended, .NET and custom string as per Unicode standard)
  • Express time interval in other time units; for example 120.seconds.in(.minutes) // 2 minutes
  • Many shortcuts to get intervals, work with time units, intervals and common date operations (isYesterday,isTomorrow,isBefore()...)

For more information, see the GitHub page of SwiftDate.

24 questions
0
votes
2 answers

DateFormatter wrong time output when a different month is selected

I have a separate DatePicker and TimePicker component in my app. Once the user has selected both the desired Date and Time, I construct a new Date object like this: let timeStamp = Date(year: selectedDate.year, month: selectedDate.month, day:…
Guy
  • 6,414
  • 19
  • 66
  • 136
0
votes
2 answers

Swift/SwiftUI: week/date management in swift

I'm working on fitness app where users selects the days he wants to exercise on. When he opens the app I wanna shown him the current week where he can observe the days his training sessions are scheduled for. If he is from the US i wanna show him a…
eugene_prg
  • 948
  • 2
  • 12
  • 25
0
votes
4 answers

How to get the current date and time of another timezone in Swift?

I have a scheduled job that needs to run against different time windows in different timezones. Ultimately, knowing UTC time when it's (for example) 20:00 in Australia, in order to kick off the job for this area. UPDATE More details about my use…
Awad
  • 823
  • 3
  • 11
  • 33
0
votes
0 answers

how to set the time to be the same as my zone if using SwiftDate pod?

I need to format this string date: "2019-01-18 10:14:52" to another string in format like this: 18 Jan 2019 - 10:14. I use SwiftDate pod to format that string date using the code below: import SwiftDate func convert(date: String, toFormat: String)…
Alexa289
  • 8,089
  • 10
  • 74
  • 178
0
votes
2 answers

Swift Date function do not work as Expected

I am trying to find out the difference between two date in seconds using Swift 4.1. This is the code I use, func getDurationInSeconds(date1 :Date) -> Int{ guard let durationInSeconds = Calendar.current.dateComponents([.second], from: Date(), to:…
Easy Coder
  • 295
  • 1
  • 3
  • 14
0
votes
1 answer

SwiftDate’s DateInRegion quarter is always 0

I’m trying to get the quarter of the year for a date but always getting a zero value when using the .quarter property. Is this a known issue or am I doing something incorrectly? Sample Code using SwiftDate 5.x: SwiftDate.defaultRegion =…
keno
  • 2,956
  • 26
  • 39
0
votes
1 answer

getting rid of a warning from SwiftDate for a reference date

I'm getting a warning from SwiftDate "[SwiftDate] Using .in() to extract calendar specific components without a reference date may return wrong values." How can I get rid of this warning? My code: let calendar = Calendar.current let birthDate =…
arakweker
  • 1,535
  • 4
  • 18
  • 40
0
votes
1 answer

SwiftDate - string to date

I use the SwiftDate library but I can't transform my string to date. This code return null let date = "Tue, 19 Sep 2017 15:43:57 GMT".date(format: .custom("EEE, dd MMM yyyy HH:mm:ss zzz")) Would anyone know why?
Louis
  • 406
  • 6
  • 13
-7
votes
2 answers

Compare two date - Swift

How can I convert string like (2019-11-02) without time to date format and get current Date device without time then compare with together?
jo jo
  • 1,758
  • 3
  • 20
  • 34
1
2