Develop

[ios] GMT Date와 Local Date 변환하기

by hooni posted Apr 07, 2015
?

Shortcut

PrevPrev Article

NextNext Article

ESCClose

Larger Font Smaller Font Up Down Go comment Print

# Local Date -> GMT Date

NSDate *localDate = <<your local date>>;

NSTimeInterval timeZoneOffset =
    [[NSTimeZone systemTimeZone] secondsFromGMTForDate:localDate];

// NOTE the "-" sign!
NSDate *gmtDate =
    [localDate dateByAddingTimeInterval:-timeZoneOffset];


# GMT Date -> Local Date

NSDate *gmtDate  = <<your gmt date>>

NSTimeInterval timeZoneOffset =
    [[NSTimeZone systemTimeZone] secondsFromGMTForDate:gmtDate];

NSDate *localDate =
    [gmtDate dateByAddingTimeInterval:timeZoneOffset];


[출처] http://stackoverflow.com/questions/1862905/nsdate-convert-date-to-gmt