Skip to content

Instantly share code, notes, and snippets.

@youngshook
Created December 4, 2017 08:44
Show Gist options
  • Save youngshook/cc473931636b31332c50d07290c65a56 to your computer and use it in GitHub Desktop.
Save youngshook/cc473931636b31332c50d07290c65a56 to your computer and use it in GitHub Desktop.
time conver
#include <time.h>
// 字符串转时间
time_t t;
struct tm tm;
strptime([iso8601String cStringUsingEncoding:NSUTF8StringEncoding], "%Y-%m-%dT%H:%M:%S%z", &tm);
tm.tm_isdst = -1;
t = mktime(&tm);
[NSDate dateWithTimeIntervalSince1970:t + [[NSTimeZone localTimeZone] secondsFromGMT]];
// 时间转字符串
time_t timeInterval = [date timeIntervalSince1970];
struct tm *cTime = localtime(&timeInterval);
NSString *triggerTime = [NSString stringWithFormat:@"%d-%02d-%02d %02d:%02d:%02d",cTime->tm_year+1900,
cTime->tm_mon+1,cTime->tm_mday,cTime->tm_hour,cTime->tm_min,cTime->tm_sec];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment