Latest 0.1.0
Homepage https://github.com/logisticinfotech/LIDateUtilitySwift
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LIDateUtility is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'LIDateUtility'

Description

Here are the full Description of How to use methods in project and it’s output.

1) Get current year

let currentYear = LIDateUtility.getCurrentYear()
print("Current year: (currentYear)")

2) Get current month

let currentMonth = LIDateUtility.getCurrentMonth()
print("Current Month: (currentMonth)")

3) Get current day

let currentDay = LIDateUtility.getCurrentDay()
print("Current Date: (currentDay)")

4) Get year from date

let year = LIDateUtility.getYearFromDate(date: date!)
print("Year of date: (year)")

5) Get month from date

let month = LIDateUtility.getMonthFromDate(date: date!)
print("Month of date: (month)")

6) Get day from date

let day = LIDateUtility.getDayFromDate(date: dDate!)
print("Day of date: (day)")

7) Get time from date

let time = LIDateUtility.getTimeFromDate(date: Date())
print(“Time: (time)”)

8) Get name of week day from date

let dayOfWeek = LIDateUtility.getWeekDayFromDate(date: Date())
print("Day of week of date: (dayOfWeek)")

9) Date from String

if let datefromstring = LIDateUtility.getDateFromString(stringDate: "01-03-2011 10:12:45", format: "dd-MM-yyyy HH:mm:ss")
{
    print("Date from string: (datefromstring)")
}

10) String from Date

let stringFromDate = LIDateUtility.getStringFromDate(date: date, format: "dd-MM-yyyy")
print("String from date: (stringFromDate)")

11) Get timestamp from date

let timeStamp = LIDateUtility.getTimestampFromDate(date: Date()) 
print("Timestamp from date: (timeStamp)")

12) Get date from timestamp

let dateFromTimestamp = LIDateUtility.getDateFromTimestamp(timeStamp: 1552292651767)
print("Date from Timestamp: (dateFromTimestamp)")

13) Get age

let date = Calendar.current.date(from: component)
if let age = LIDateUtility.getAge(birthDate: date!)
{
    print("nAge: (age)")
}
else
{
    print("nAge: Invalid birth date")
}

14) Compare Two Dates

let comparisonString = LIDateUtility.compareDates(date1: Date(), date2: date)) 
print("Comparison of dates: (comparisonString)")

15) Get Difference between two dates in days

let differenceInDays = LIDateUtility.getDifferenceBetweenTwoDatesInDays(date1: Date(), date2: date!) 
print("Difference of days: (differenceInDays)")

16) Get Difference between two dates in months

let differenceInMonths = LIDateUtility.getDifferenceBetweenTwoDatesInMonths(date1: Date(), date2: date!)
print("Difference of months: (differenceInMonths)")

17) Get Difference between two dates in years

let differenceInYears = LIDateUtility.getDifferenceBetweenTwoDatesInYears(date1: Date(), date2: date!)
print("Difference of years: (differenceInYears)")

18) Get Difference between two dates in hours

let differenceInHours = LIDateUtility.getDifferenceBetweenTwoDatesInHours(date1: Date(), date2: date!)
print("Difference of hours: (differenceInHours)")

19) Get Difference between two dates in minutes

let differenceInMinutes = LIDateUtility.getDifferenceBetweenTwoDatesInMinutes(date1: Date(), date2: date!)
print("Difference of minutes: (differenceInMinutes)")

20) Get Difference between two dates in seconds

let differenceInSeconds = LIDateUtility.getDifferenceBetweenTwoDatesInSeconds(date1: Date(), date2: date!)
print("Difference of seconds: (differenceInSeconds)")

21) Add number of days to date :

let newDate = LIDateUtility.addNumberOfDaysToDate(date: Date(), count: 4)
print("Date by adding days: (newDate)")

22) Add number of months to date :

let newDate = LIDateUtility.addNumberOfMonthsToDate(date: Date(), count: 7)
print("Date by adding months: (newDate)")

23) Add number of years to date

let newDate = LIDateUtility.addNumberOfYearsToDate(date: Date(), count: 2)
print("Date by adding years: (newDate)")

24) Add number of hours to date

let newDate = LIDateUtility.addNumberOfHoursToDate(date: Date(), count: 5)
print("Date by adding hours: (newDate)")

25) Add number of minutes to date

let newDate = LIDateUtility.addNumberOfMinutesToDate(date: Date(), count: 60)
print("Date by adding minutes: (newDate)")

26) Add number of seconds to date

let newDate = LIDateUtility.addNumberOfSecondsToDate(date: Date(), count: 60)
print("Date by adding seconds: (newDate)")

27) Subtract(Minus) number of days from date

let newDate = LIDateUtility.subtractNumberOfDaysFromDate(date: Date(), count: 6)
print("Date by subtracting days: (newDate)")

28) Subtract(Minus) number of months from date

let newDate = LIDateUtility.subtractNumberOfMonthsFromDate(date: Date(), count: 4)
print("Date by subtracting months: (newDate)")

29) Subtract(Minus) number of years from date

let newDate = LIDateUtility.subtractNumberOfYearsFromDate(date: Date(), count: 10)
print("Date by subtracting years: (newDate)")

30) Subtract(Minus) number of hours from date :

let newDate = LIDateUtility.subtractNumberOfHoursFromDate(date: Date(), count: 4)
print("Date by subtracting hours: (newDate)")

31) Subtract(Minus) number of minutes from date :

let newDate = LIDateUtility.subtractNumberOfMinutesFromDate(date: Date(), count: 60)
print("Date by subtracting minutes: (newDate)")

32) Subtract(Minus) number of seconds from date :

let newDate = LIDateUtility.subtractNumberOfSecondsFromDate(date: Date(), count: 120)
print("Date by subtracting seconds: (newDate)")

33) Check if date is today’s date

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”)
}

34) Check if week day of date is weekend

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”)
}

35) Convert local time to UTC time

if let utcDate = LIDateUtility.convertLocalTimeToUTC(date: Date())
{
    print("Local: (Date()) || UTC: (utcDate)")
}
else
{
    print("Local to UTC: Can't convert")
}

36) Convert UTC time to local time

if let localDate = LIDateUtility.convertUTCTimeToLocal(date: utcdate)
{
    print("UTC: (utcdate) || Local: (localDate)")
}
else
{
    print("UTC to Local: Can't convert")
}

37) Get current timezone

let timeZone = LIDateUtility.getCurrentTimeZone()
print(“Current timezone: (timeZone)”)

38) Get timezone from identifier

if let timeZone = LIDateUtility.getTimeZoneBy(id: "America/Los_Angeles")
{
    print("TimeZone by Id: (timeZone.identifier)")
}
else
{
    print("TimeZone by Id: Incorrect Id")
}

License

LIDateUtility is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "LIDateUtility",
    "version": "0.1.0",
    "summary": "LIDateUtility help you to give you many date option in just one function",
    "description": "TODO: Add long description of the pod here.",
    "homepage": "https://github.com/logisticinfotech/LIDateUtilitySwift",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Bhavin Bera": "[email protected]"
    },
    "source": {
        "git": "https://github.com/logisticinfotech/LIDateUtilitySwift.git",
        "tag": "0.1.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "LIDateUtility/Classes/**/*"
}

Pin It on Pinterest

Share This