TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Mar 2017 |
Maintained by 李亚军.
To run the example project, clone the repo, and run 'pod install' from the Example directory first.
1: 引入头文件 #import <LYJDateService/LYJDateService-umbrella.h>
2: 使用实例
/**
LYJDateService demo 测试
*/
- (void)LYJDateServiceTest {
// 注意: 输入的时间格式 TimeString 必须与后面的时间格式表达式 timeFormatter 保持一致,不然会报错
NSTimeInterval timeInterval = [LYJDateService timeStringToTimestampWithTimeString:@"2017/10/25 13:30:30:288" timeFormatter:@"yyyy/MM/dd HH:mm:ss:SSS"];
NSLog(@"TimeInterval is %.3f" , timeInterval); // 结果: imeInterval is 1508909430.288
NSString *timeString = [LYJDateService timestampToDateStringWithTimeStamp:timeInterval timeFormatter:@"yyyy年MM月dd日 HH时:mm分:ss秒.SSS毫秒"];
NSLog(@"timeString is %@" , timeString); // 结果: timeString is 2017年10月25日 13时:30分:30秒.288毫秒
NSTimeInterval todayTimeInterval = [LYJDateService getOneDayTimestampFromTodayWithDayNumber:0];
NSLog(@"todayTimeInterval is %.f" , todayTimeInterval); // 结果: todayTimeInterval is 1490671288
NSLog(@"today is %@" , [LYJDateService timestampToDateStringWithTimeStamp:todayTimeInterval timeFormatter:@"yyyy年MM月dd日"]); // 结果: today is 2017年03月28日
NSTimeInterval tomorrowTimeInterval = [LYJDateService getOneDayTimestampFromTodayWithDayNumber:1];
NSLog(@"tomorrowTimeInterval is %.f" , tomorrowTimeInterval); // 结果: tomorrowTimeInterval is 1490757688
NSLog(@"tomorrow is %@" , [LYJDateService timestampToDateStringWithTimeStamp:tomorrowTimeInterval timeFormatter:@"yyyy年MM月dd日"]); // 结果: tomorrow is 2017年03月29日
NSTimeInterval yesterdayTimeInterval = [LYJDateService getOneDayTimestampFromTodayWithDayNumber:-1];
NSLog(@"yesterdayTimeInterval is %.f" , yesterdayTimeInterval); // 结果: yesterdayTimeInterval is 1490585331
NSLog(@"yestoday is %@" , [LYJDateService timestampToDateStringWithTimeStamp:yesterdayTimeInterval timeFormatter:@"yyyy年MM月dd日"]); // 结果: yestoday is 2017年03月27日
NSTimeInterval todayTimeIntervalCurrent = [LYJDateService getOneDayTimestampFromTodayWithDayNumber:0 delayHourTime:0];
NSLog(@"todayTimeIntervalCurrent is %.f , date is %@" , todayTimeIntervalCurrent , [LYJDateService timestampToDateStringWithTimeStamp:todayTimeIntervalCurrent timeFormatter:@"yyyy/MM/dd HH:mm:ss"]); // 结果: todayTimeIntervalCurrent is 1490673096 , date is 2017/03/28 11:51:36
NSTimeInterval todayTimeIntervalDelayOneHour = [LYJDateService getOneDayTimestampFromTodayWithDayNumber:0 delayHourTime:1];
NSLog(@"todayTimeIntervalDelayOneHour is %.f , date is %@" , todayTimeIntervalCurrent , [LYJDateService timestampToDateStringWithTimeStamp:todayTimeIntervalDelayOneHour timeFormatter:@"yyyy/MM/dd HH:mm:ss"]); // 结果: todayTimeIntervalDelayOneHour is 1490673096 , date is 2017/03/28 12:51:36
NSString *weekString = [LYJDateService getOneDayWeekFromTodayWithDayNumber:0 weekArray:nil];
NSLog(@"weekString is %@" , weekString); // 结果: weekString is 周二
NSString *weekStringTimestamp = [LYJDateService getOneDayWeekFromOnedayTimestamp:tomorrowTimeInterval dayNumber:0 weekArray:@[@"星期日" , @"星期一" , @"星期二" , @"星期三" , @"星期四" , @"星期五" , @"星期六" , @"星期日"]];
NSLog(@"weekStringTimestamp is %@" , weekStringTimestamp); // 结果: weekStringTimestamp is 星期三
}
LYJDateService is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "LYJDateService"
li625317534, [email protected]
LYJDateService is available under the MIT license. See the LICENSE file for more info.