QMDateManager.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // QMDateManager.m
  3. // IMSDK-OC
  4. //
  5. // Created by haochongfeng on 2017/5/17.
  6. // Copyright © 2017年 HCF. All rights reserved.
  7. //
  8. #import "QMDateManager.h"
  9. @implementation QMDateManager
  10. + (NSString *)showChatTime:(NSString *)timeT {
  11. NSString * str = @"";
  12. UInt64 msgTime = timeT.longLongValue;
  13. UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000;
  14. UInt64 dxTime = recordTime - msgTime;
  15. if (dxTime<60*1000) {
  16. //几秒前
  17. str = [NSString stringWithFormat:@"%llu 秒前",dxTime/1000];
  18. }else if (60*1000<dxTime && dxTime<60*60*1000) {
  19. //几分钟前
  20. str = [NSString stringWithFormat:@"%llu 分钟前",dxTime/(60*1000)];
  21. }else if (dxTime > 60*60*1000) {
  22. NSString * string = [NSString stringWithFormat:@"%@",timeT];
  23. NSDate * date = [NSDate dateWithTimeIntervalSince1970:string.doubleValue/1000];
  24. NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
  25. [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
  26. formatter.formatterBehavior = NSDateFormatterBehaviorDefault;
  27. formatter.timeZone= [NSTimeZone timeZoneWithAbbreviation:@"UTC"];
  28. NSTimeZone * zone = [NSTimeZone systemTimeZone];
  29. NSInteger inv = [zone secondsFromGMTForDate:date];
  30. NSTimeInterval timeInv = inv;
  31. NSDate * newDate = [date dateByAddingTimeInterval:timeInv];
  32. str = [formatter stringFromDate:newDate];
  33. }
  34. return str;
  35. }
  36. @end