To run the example project, clone the repo, and run pod install
from the Example directory first.
LIDateUtility is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LIDateUtility'
Here are the full Description of How to use methods in project and it's output.
let currentYear = LIDateUtility.getCurrentYear()
print("Current year: \(currentYear)")
let currentMonth = LIDateUtility.getCurrentMonth()
print("Current Month: \(currentMonth)")
let currentDay = LIDateUtility.getCurrentDay()
print("Current Date: \(currentDay)")
let year = LIDateUtility.getYearFromDate(date: date!)
print("Year of date: \(year)")
let month = LIDateUtility.getMonthFromDate(date: date!)
print("Month of date: \(month)")
let day = LIDateUtility.getDayFromDate(date: dDate!)
print("Day of date: \(day)")
let time = LIDateUtility.getTimeFromDate(date: Date())
print(“Time: \(time)”)
let dayOfWeek = LIDateUtility.getWeekDayFromDate(date: Date())
print("Day of week of date: \(dayOfWeek)")
if let datefromstring = LIDateUtility.getDateFromString(stringDate: "01-03-2011 10:12:45", format: "dd-MM-yyyy HH:mm:ss")
{
print("Date from string: \(datefromstring)")
}
let stringFromDate = LIDateUtility.getStringFromDate(date: date, format: "dd-MM-yyyy")
print("String from date: \(stringFromDate)")
let timeStamp = LIDateUtility.getTimestampFromDate(date: Date())
print("Timestamp from date: \(timeStamp)")
let dateFromTimestamp = LIDateUtility.getDateFromTimestamp(timeStamp: 1552292651767)
print("Date from Timestamp: \(dateFromTimestamp)")
let date = Calendar.current.date(from: component)
if let age = LIDateUtility.getAge(birthDate: date!)
{
print("\nAge: \(age)")
}
else
{
print("\nAge: Invalid birth date")
}
let comparisonString = LIDateUtility.compareDates(date1: Date(), date2: date))
print("Comparison of dates: \(comparisonString)")
let differenceInDays = LIDateUtility.getDifferenceBetweenTwoDatesInDays(date1: Date(), date2: date!)
print("Difference of days: \(differenceInDays)")
let differenceInMonths = LIDateUtility.getDifferenceBetweenTwoDatesInMonths(date1: Date(), date2: date!)
print("Difference of months: \(differenceInMonths)")
let differenceInYears = LIDateUtility.getDifferenceBetweenTwoDatesInYears(date1: Date(), date2: date!)
print("Difference of years: \(differenceInYears)")
let differenceInHours = LIDateUtility.getDifferenceBetweenTwoDatesInHours(date1: Date(), date2: date!)
print("Difference of hours: \(differenceInHours)")
let differenceInMinutes = LIDateUtility.getDifferenceBetweenTwoDatesInMinutes(date1: Date(), date2: date!)
print("Difference of minutes: \(differenceInMinutes)")
let differenceInSeconds = LIDateUtility.getDifferenceBetweenTwoDatesInSeconds(date1: Date(), date2: date!)
print("Difference of seconds: \(differenceInSeconds)")
let newDate = LIDateUtility.addNumberOfDaysToDate(date: Date(), count: 4)
print("Date by adding days: \(newDate)")
let newDate = LIDateUtility.addNumberOfMonthsToDate(date: Date(), count: 7)
print("Date by adding months: \(newDate)")
let newDate = LIDateUtility.addNumberOfYearsToDate(date: Date(), count: 2)
print("Date by adding years: \(newDate)")
let newDate = LIDateUtility.addNumberOfHoursToDate(date: Date(), count: 5)
print("Date by adding hours: \(newDate)")
let newDate = LIDateUtility.addNumberOfMinutesToDate(date: Date(), count: 60)
print("Date by adding minutes: \(newDate)")
let newDate = LIDateUtility.addNumberOfSecondsToDate(date: Date(), count: 60)
print("Date by adding seconds: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfDaysFromDate(date: Date(), count: 6)
print("Date by subtracting days: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfMonthsFromDate(date: Date(), count: 4)
print("Date by subtracting months: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfYearsFromDate(date: Date(), count: 10)
print("Date by subtracting years: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfHoursFromDate(date: Date(), count: 4)
print("Date by subtracting hours: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfMinutesFromDate(date: Date(), count: 60)
print("Date by subtracting minutes: \(newDate)")
let newDate = LIDateUtility.subtractNumberOfSecondsFromDate(date: Date(), count: 120)
print("Date by subtracting seconds: \(newDate)")
let isToday = LIDateUtility.isToday(date: date)
If isToday
{
print(“The date: \(date) is today’s date”)
}
else
{
print(“The date: \(date) is not today’s date”)
}
let isWeekend = LIDateUtility.isWeekEnd(date: date)
If isWeekend
{
print(“The weekday of date: \(date) is weekend”)
}
else
{
print(“The weekday of date: \(date) is not weekend”)
}
if let utcDate = LIDateUtility.convertLocalTimeToUTC(date: Date())
{
print("Local: \(Date()) || UTC: \(utcDate)")
}
else
{
print("Local to UTC: Can't convert")
}
if let localDate = LIDateUtility.convertUTCTimeToLocal(date: utcdate)
{
print("UTC: \(utcdate) || Local: \(localDate)")
}
else
{
print("UTC to Local: Can't convert")
}
let timeZone = LIDateUtility.getCurrentTimeZone()
print(“Current timezone: \(timeZone)”)
if let timeZone = LIDateUtility.getTimeZoneBy(id: "America/Los_Angeles")
{
print("TimeZone by Id: \(timeZone.identifier)")
}
else
{
print("TimeZone by Id: Incorrect Id")
}
LIDateUtility is available under the MIT license. See the LICENSE file for more info.