You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.4 KiB
102 lines
3.4 KiB
![]()
2 years ago
|
//
|
||
|
// NSString+methods.m
|
||
![]()
1 year ago
|
// FireBoltt
|
||
![]()
2 years ago
|
//
|
||
|
// Created by lemo on 2018/6/12.
|
||
|
// Copyright © 2020年 ecell. All rights reserved.
|
||
|
//
|
||
|
|
||
|
#import "NSString+methods.h"
|
||
|
|
||
|
@implementation NSString (methods)
|
||
|
//将NSDate按yyyy-MM-dd格式时间输出 判断是否是当日时间
|
||
|
+(NSString*)NsdateToString:(NSDate *)date
|
||
|
{
|
||
|
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
|
||
|
[dateFormat setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
[dateFormat setDateFormat:@"yyyy-MM-dd"];
|
||
|
NSString* string=[dateFormat stringFromDate:date];
|
||
|
return string;
|
||
|
}
|
||
|
|
||
|
//将yyyy-MM-dd格式时间转换成时间戳
|
||
|
+(long long)changeTimeToSecond:(NSString *)timeStr
|
||
|
{
|
||
|
long long time;
|
||
|
NSDateFormatter *format=[[NSDateFormatter alloc] init];
|
||
|
[format setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
[format setDateFormat:@"yyyy-MM-dd"];
|
||
|
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
|
||
|
[format setTimeZone:timeZone];
|
||
|
NSDate *fromdate=[format dateFromString:timeStr];
|
||
|
time= (long long)[fromdate timeIntervalSince1970] *1000;
|
||
|
// HQLog(@"%ld",time);
|
||
|
return time;
|
||
|
}
|
||
|
|
||
|
//将yyyy-MM-dd-HH-mm 格式时间转换成时间戳
|
||
|
+(long)changeTimeToMinutes:(NSString *)timeStr{
|
||
|
long time = 0;
|
||
|
NSDateFormatter *format=[[NSDateFormatter alloc] init];
|
||
|
[format setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
NSInteger count = [timeStr componentsSeparatedByString:@"-"].count;
|
||
|
if (count == 5) {
|
||
|
[format setDateFormat:@"yyyy-MM-dd-HH-mm"];
|
||
|
}
|
||
|
if (count == 6) {
|
||
|
[format setDateFormat:@"yyyy-MM-dd-HH-mm-ss"];
|
||
|
}
|
||
|
NSDate *fromdate=[format dateFromString:timeStr];
|
||
|
time= (long)[fromdate timeIntervalSince1970];
|
||
|
// HQLog(@"%ld",time);
|
||
|
return time;
|
||
|
}
|
||
|
|
||
|
//将yyyy-MM-dd HH:mm格式时间转换成时间戳
|
||
|
+(long)changeTimeToTimeSp:(NSString *)timeStr
|
||
|
{
|
||
|
long time = 0;
|
||
|
NSDateFormatter *format=[[NSDateFormatter alloc] init];
|
||
|
[format setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
[format setDateFormat:@"yyyy-MM-dd HH:mm"];
|
||
|
NSDate *fromdate=[format dateFromString:timeStr];
|
||
|
time= (long)[fromdate timeIntervalSince1970];
|
||
|
// HQLog(@"%ld",time);
|
||
|
return time;
|
||
|
}
|
||
|
|
||
|
//将NSDate按yyyy-MM-dd HH:mm:ss格式时间输出
|
||
|
+(NSString*)nsdateToString:(NSDate *)date
|
||
|
{
|
||
|
NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
|
||
|
[dateFormat setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
||
|
NSString* string=[dateFormat stringFromDate:date];
|
||
|
NSLog(@"string - %@",string);
|
||
|
return string;
|
||
|
}
|
||
|
|
||
|
//将yyyy-MM-dd HH:mm:ss格式时间转换成时间戳
|
||
|
+(long)changeTimeToTimeStamp:(NSString *)timeStr
|
||
|
{
|
||
|
long time;
|
||
|
NSDateFormatter *format=[[NSDateFormatter alloc] init];
|
||
|
[format setCalendar: [[NSCalendar alloc]
|
||
|
initWithCalendarIdentifier:NSCalendarIdentifierGregorian]];
|
||
|
[format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
|
||
|
NSDate *fromdate=[format dateFromString:timeStr];
|
||
|
time= (long)[fromdate timeIntervalSince1970];
|
||
|
// HQLog(@"%ld",time);
|
||
|
return time;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
@end
|