iphone - NSDateComponents returning strange hour -


I am writing some code to get images while on a server image file name is in yyyyMMdd_HHmm format (UTC ) And generated every 3 hours (1200, 1500, 1800, .. etc). When the code starts, I get the current UTC date and take time out. After this, I create an NSDateComponent from this, and while setting the current time, set the time of NSDateComponent in the time of the next image. Very strange, if I set it to 3 hours, then NSDTit gets a different hour from NSCalendar dateFromComponents ... what does it give? (I've also added to the console output too).

Get the current time in UTC NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; NSTimeZone * UTC = [NSTimeZone timezonename: @ "UTC"]; [Date-time setterzone: UTC]; // Get current hours; Minute [dateFormatter setDateFormat: @ "HHM"]]; NSDT * today = [NSDT date]; NSString * str = [dateFormatter stringFromDate: today]; NSInteger hour = [str integerValue]; NSLog (STR); // Find the next image time NSCAL Calendar * cal = [[NSCalendar alloc] initWithCalendarIdentifier: NSGgorian Calendar]; Unsigned unit flags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHOR calendarUnit | NSMinuteCalendarUnit; NSDateComponents * currentImageDateComps = [KAL components: Date with unitFAG: today]; If (Hour> 2100) {[Present Image Cops Set Horoscope: 0]; // Add an extra day as the next day - Start the new day [currentImageDateComps setDay: [currentImageDateComps day] +1]; } And if (bell> 300) {[currentImageDateComps setHour: 3]; } And if (hours & lt; 600) {[currentImageDateComps setHour: 6]; } And if (bell> 900) {[currentImageDateComps setHour: 9]; } And if (bell <1200) {[currentImageDateComps setHour: 12]; } And if (bell> 1500) {[currentImageDateComps setHour: 15]; } And if (hour <1800) {[currentImageDateComps setHour: 18]; } And if (bell> 2100) {[currentImageDateComps setHour: 21]; } [Current Image Cones Setting Minutes: 0]; NSLog (@ "hour% d", [current image imagines]]; NSLog (@ "min% d", [current image imagines min]); // Create Date NSDate * currentImageDate = [cal dateFromComponents: currentImageDateComps]; [DateFormatter setDateFormat: @ "yyyyMMdd_hhmm"]; NSString * Next image = [dateFormatter stringFromDate: currentImageDate]; Self.currentFilename = [Next Image Stringbapping String: @ ".png"]; NSLog (self.currentFilename);

The console output created from NSLogs is this. I get 3 hours worth, but it gets back in the form of '1700'?

2010-01-25 12: 25: 02.049 Predict [8447: 207] ViewDidload

2010-01-25 12: 25: 02.052 Forecasting [8447: 207] 0225

2010-01-25 12: 25: 02.052 predictions [8447: 207] hours 3

2010-01-25 12: 25: 02.053 predictions [8447: 207] min 0

2010-01-25 12: 25: 02.053 Forecasting [8447: 207] 20100124_1700.png

(I know there are some issues of memory release but I want to make it functional first ..)

Can there be a time zone issue?


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -