简体   繁体   中英

convert NSDate to GMT timezone

I am working on NSDate and i am new for it.I have start date and end date,getting from user.And it is 2013-01-01 and 2013-02-19 .When i try to display in console it is showing me 2012-12-31 18:30:00 +0000 .So you can say 5:30 is gap.So i am adding time interval

startDate = [aStartdDate dateByAddingTimeInterval:19800];
endDate = [aEndDate dateByAddingTimeInterval:19800];

My question is when i am trying to get current week using 2012-12-31 18:30:00 +0000 date, it is showing me correctly.But when i use 2013-02-01 00:00:00 +0000 date,it is showing me total number of weeks in month.Please help me.Thanking you.

Timezones shouldn't be part of your model - They are a presentation problem.
Your model should always use a common default timezone. If you present the date to your users, apply a NSDateFormatter that uses a specific timezone .

In your case this means, that you shouldn't try to fix your dates by applying arbitrary intervals but use a date formatter in the final step (output) instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM