94 lines
3.1 KiB
Objective-C
94 lines
3.1 KiB
Objective-C
//
|
|
// GiGaHelper.m
|
|
// GIGA
|
|
//
|
|
// Created by lianxiang on 2018/8/13.
|
|
// Copyright © 2018年 com.giga.ios. All rights reserved.
|
|
//
|
|
|
|
#import "GiGaHelper.h"
|
|
|
|
@implementation GiGaHelper
|
|
|
|
+(NSString *) getNowTimeString{
|
|
|
|
NSDate *now = [NSDate date];
|
|
NSDateFormatter *formatDate = [[NSDateFormatter alloc] init];
|
|
formatDate.dateFormat= @"yyyy-MM-dd hh:mm:ss";
|
|
NSString *dayStr = [formatDate stringFromDate:now];
|
|
|
|
return dayStr;
|
|
}
|
|
|
|
+(long) timeStampWithDate:(NSDate *) timeDate{
|
|
long timeStamp = 0;
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
|
|
NSString *timeString = [formatter stringFromDate:timeDate];
|
|
NSDate *date = [formatter dateFromString:timeString];
|
|
timeStamp = (long)[date timeIntervalSince1970];
|
|
|
|
return timeStamp;
|
|
}
|
|
|
|
+ (NSString *) dateWithTimeStamp:(long) longValue{
|
|
|
|
long value = longValue;
|
|
NSDateFormatter *formatDay = [[NSDateFormatter alloc] init];
|
|
formatDay.dateFormat = @"yyyy-MM-dd hh:mm:ss";
|
|
NSNumber *time = [NSNumber numberWithLong:value];
|
|
//转换成NSTimeInterval
|
|
NSTimeInterval nsTimeInterval = [time longValue];
|
|
NSDate *date = [[NSDate alloc] initWithTimeIntervalSince1970:nsTimeInterval];
|
|
NSString *dayStr = [formatDay stringFromDate:date];
|
|
return dayStr;
|
|
|
|
}
|
|
|
|
+(long)getFutureTimetstamp:(NSUInteger)hour minute:(NSUInteger)min second:(NSUInteger)second{
|
|
|
|
NSDate *datenow = [NSDate date];
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
[formatter setDateFormat:@"YYYY年MM月dd日HH:mm:ss"];
|
|
NSTimeInterval timeInterval = hour * 3600 + min * 60 + second;
|
|
NSDate *futrueDate = [datenow dateByAddingTimeInterval:timeInterval];
|
|
NSString *futrueTimeStr = [formatter stringFromDate:futrueDate];
|
|
NSDate *furtureformatDate = [formatter dateFromString:futrueTimeStr];
|
|
long futrueTimestamp= [furtureformatDate timeIntervalSince1970];
|
|
|
|
return futrueTimestamp;
|
|
|
|
}
|
|
|
|
+(long)getNowDateTimestamp{
|
|
|
|
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
|
|
// ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
|
|
[formatter setDateFormat:@"YYYY年MM月dd日HH:mm:ss"];
|
|
|
|
//现在时间,你可以输出来看下是什么格式
|
|
NSDate *datenow = [NSDate date];
|
|
//----------将nsdate按formatter格式转成NSString
|
|
NSString *currentTimeString_1 = [formatter stringFromDate:datenow];
|
|
NSDate *applyTimeString_1 = [formatter dateFromString:currentTimeString_1];
|
|
long nowTimeSp = (long)[applyTimeString_1 timeIntervalSince1970];
|
|
return nowTimeSp;
|
|
}
|
|
|
|
+(NSString *)stringWithNSTimerinterval:(NSTimeInterval)interval{
|
|
|
|
NSInteger hour = interval / (60*60);
|
|
NSInteger min = interval / 60;
|
|
NSInteger sec = (NSInteger) interval % 60;
|
|
return [NSString stringWithFormat:@"%02ld:%02ld:%02ld",hour,min,sec];
|
|
|
|
}
|
|
|
|
//计算文字的长度
|
|
+ (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
|
|
{
|
|
return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil].size;
|
|
}
|
|
|
|
@end
|