DateUnixTime
Description
DateUnixTime is a lightweight Objective-C framework that provides convenient methods to convert between Unix timestamps and NSDate objects in iOS.
Features
- Convert Unix timestamps to NSDate objects
- Convert NSDate objects to Unix timestamps
- Support for both local and GMT timestamps
- Easy-to-use API with intuitive methods
- Highly customizable for various date formats
Installation
To integrate DateUnixTime into your iOS project, follow these steps:
- Install DateUnixTime via Cocoapods by adding the following line to your Podfile:
pod 'DateUnixTime'
- Run the command
pod install
in your terminal - Open your project in Xcode using the
.xcworkspace
file
Usage
Using DateUnixTime is straightforward and requires minimal code. Here are some common use cases:
Converting Unix Timestamps to NSDate Objects
To convert a Unix timestamp to an NSDate object, use the method dateFromUnixTime:
. Here is an example:
NSDate *date = [DateUnixTime dateFromUnixTime:1617032325];
Converting NSDate Objects to Unix Timestamps
To convert an NSDate object to a Unix timestamp, use the method unixTimeFromDate:
. Here is an example:
NSTimeInterval timestamp = [DateUnixTime unixTimeFromDate:[NSDate date]];
Converting Local and GMT Timestamps
By default, DateUnixTime uses local timestamps. To convert GMT timestamps instead, use the useGMT:
property. Set it to YES
to utilize GMT timestamps. Example:
[DateUnixTime shared].useGMT = YES;
Customizing Date Formats
DateUnixTime allows you to customize the date format when converting to a string representation. By default, it uses the format “yyyy-MM-dd HH:mm:ss”. To change the format, use the dateFormat
property. Example:
[DateUnixTime shared].dateFormat = @"dd MMM yyyy";
Contributing
Contributions to DateUnixTime are welcome! If you find a bug or have suggestions for improvement, please open an issue or submit a pull request on the project’s GitHub repository.
License
DateUnixTime is released under the MIT license. See LICENSE for more details.