Datetime - Kelmatou/iOSTools GitHub Wiki
Nested Types
enum Month: String {
case January = "January"
case February = "February"
case March = "March"
case April = "April"
case May = "May"
case June = "June"
case July = "July"
case August = "August"
case September = "September"
case October = "October"
case November = "November"
case December = "December"
}
enum WeekDay: String {
case Monday = "Monday"
case Tuesday = "Tuesday"
case Wednesday = "Wednesday"
case Thursday = "Thursday"
case Friday = "Friday"
case Saturday = "Saturday"
case Sunday = "Sunday"
}
Properties
var year: Int
var month: Int
var day: Int
var hour: Int
var minute: Int
var second: Int
var monthName: String
var weekday: String
var weekdayIndex: Int
Inits
init()
init(date: Date)
init?(year: Int, month: Int, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0, timeZone: TimeZone? = nil)
init?(dateTime: Datetime, timeZone: TimeZone)
init?(string: String, format: String)
Methods
func datetimeByAdding(year: Int = 0, month: Int = 0, day: Int = 0, hour: Int = 0, minute: Int = 0, second: Int = 0) -> Datetime?
func intervalFrom1970() -> Double?
func toString(format: String = "yyyy/MM/dd hh:mm:ss") -> String
Statics
func monthFromInt(_ val: Int) -> Month?
func weekDayFromInt(_ val: Int) -> WeekDay?
func interval(from date1: Datetime, to date2: Datetime) -> Double?
Operators
Datetime == Datetime
Datetime < Datetime
Definitions
-
var year: Int
: The year contained in current Datetime object. -
var month: Int
: The month contained in current Datetime object. Value goes from 1 to 12. -
var day: Int
: The day contained in current Datetime object. Value goes from 1 to 31. -
var hour: Int
: The hour contained in current Datetime object. Values goes from 0 to 12. -
var minute: Int
: The minute contained in current Datetime object. Values goes from 0 to 59. -
var second: Int
: The second contained in current Datetime object. Values goes from 0 to 59. -
var monthName: String
: The name of the month contained in current Datetime object. -
var weekday: String
: The name of the day in week contained in current Datetime object. -
var weekdayIndex: Int
: The index of the day in week contained in current Datetime object. Value goes from 0 to 6. -
init()
: Create a Datetime with current time. -
init(date: Date)
: Create a Datetime with a specified date. -
init?(year: Int, month: Int, day: Int, hour: Int = 0, minute: Int = 0, second: Int = 0, timeZone: TimeZone? = nil)
: Create a Datetime from all date components. Only year, month and day are required. If any of those parameters is not valid, nil will be returned. -
init?(dateTime: Datetime, timeZone: TimeZone)
: Create a Datetime from an existing datetime, but converts it in timeZone date. -
init?(string: String, format: String)
: Create a Datetime from string, specifying format to parse it. In format String, you can write (a maximum of 1 time each symbol):- "yyyy" = year (required)
- "MM" = month (required)
- "dd" = day (required)
- "hh" = hour (optional)
- "mm" = minute (optional)
- "ss" = second (optional)
In case parsing failed or value was not present/invalid, nil will be returned.
-
func datetimeByAdding(year: Int = 0, month: Int = 0, day: Int = 0, hour: Int = 0, minute: Int = 0, second: Int = 0) -> Datetime?
: Add values to current Datetime object to create a new Datetime. Those values can be negative. Nil will be returned in case date cannot be represented. -
func intervalFrom1970() -> Double?
: Get the number of seconds from 1st of January 1970 00:00:00 to current Datetime. -
func toString(format: String = "yyyy/MM/dd hh:mm:ss") -> String
: Generate a String with format. Following symbols will be replaced by their corresponding value:- "yyyy" = year
- "yy" = last 2 digits of year
- "MM" = month
- "dd" = day
- "hh" = hour
- "mm" = minute
- "ss" = second
-
static func monthFromInt(_ val: Int) -> Month?
: Attempt to convert val into Month enum value. If value is lower than 1 or greater than 12, returns nil. -
static func weekDayFromInt(_ val: Int) -> WeekDay?
: Attempt to convert val into WeekDay enum value. If value is lower than 0 or greater than 6 returns nil. -
static func interval(from date1: Datetime, to date2: Datetime) -> Double?
: Get the number of seconds between date1 and date2. -
Datetime == Datetime
: is true if year, month, day, hour, minute and second are equal. -
Datetime < Datetime
: is true if left Datetime is before right Datetime.