Questions tagged [nstimezone]

Time Zone data for iOS and Mac OS X

NSTimeZone is a class that presents IANA time zone data as an Objective-C () class. It's part of the Foundation framework () on Mac OS X () and iOS () and in Cocotron and GNUStep.

255 questions
8
votes
5 answers

NSDate independent of timezone?

I have an app that displays a timetable of certain ferry trips. If I travel to a different timezone - say 4 hours behind, a 10am ferry trip now shows up as 6am? I know this has got to do with how dates are treated based on their timezones, but I…
Rog
  • 18,602
  • 6
  • 76
  • 97
8
votes
2 answers

Get number of days between two NSDate dates in a particular timezone

I found the codes to calculate days difference between two dates here. I write a method : -(NSInteger)daysWithinEraFromDate:(NSDate *) startDate toDate:(NSDate *) endDate { NSCalendar *gregorian = [[NSCalendar alloc] …
Vigor
  • 1,706
  • 3
  • 26
  • 47
7
votes
1 answer

NSTime: Why [NSDateComponent date] returns nil here?

I want to convert a NSDate from one timezone to another. Here is my code: NSDate* convertTime(NSDate* fromDate, NSTimeZone* fromTimeZone, NSTimeZone* toTimeZone) { if (fromTimeZone == toTimeZone) { return fromDate; } …
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
6
votes
1 answer

Set specific timezone globally for app to use

I'm writing an app that needs to display and calculate all dates, times, timeintervals etc. from a specific, given timezone in Europe. Meaning, if I'm, say, in Paris, the app works flawlessly now, but if I go to New York, the app should display and…
JiaYow
  • 5,207
  • 3
  • 32
  • 36
6
votes
2 answers

NSCalendar dateFromComponents: GMT timezone instead of systemTimeZone

This code NSCalendar *calendar =[NSCalendar currentCalendar]; [gregorian setTimeZone:tz]; NSLog(@"%@", [gregorian timeZone]); NSDateComponents *comp = [gregorian components:(NSYearCalendarUnit | NSMonthCalendarUnit) fromDate:[NSDate date]]; [comp…
Mitry
  • 375
  • 4
  • 13
6
votes
2 answers

What is Difference among following time zones in swift

let timeZone = NSTimeZone.system.description let localTimeZone = TimeZone.ReferenceType.local.description let currentTimeZone = TimeZone.current.description let defaultTimeZone = TimeZone.ReferenceType.default.description let autoUpdateTimezon =…
Jaydeep Vyas
  • 4,411
  • 1
  • 18
  • 44
6
votes
2 answers

Storing an absolute NSDate, not relative to a timezone

I am creating an iOS app to track attendance. Each attendance entry is stored in an object which has a status attribute (e.g. present, absent) and an NSDate attribute called date which denotes the day which that attendance record was taken. When I…
Skoota
  • 5,280
  • 9
  • 52
  • 75
5
votes
1 answer

NSDatePicker timezone weirdness

I have an NSDatePicker in my nib file. In code, I set it's timezone to be the GMT calendar's timezone: [datePicker setTimeZone:[calendar timeZone]]; I only really care about the time (hours, minutes) on the datepicker which I populate…
JPC
  • 8,096
  • 22
  • 77
  • 110
5
votes
1 answer

Do NSDate's in CoreData encapsulate time zone?

I keep dates and times in my CoreData store and need to accurately present to users the time as originally entered. The problem is that if they entered 4:00 on the East Coast, then later look at the recorded time on the West Coast, it appears as…
ed94133
  • 1,477
  • 2
  • 19
  • 40
5
votes
2 answers

NSDate behaviour when saving to plist

I am creating a date from [NSdate date] and saving it to plist, Here is how I am creating a date - (void)applicationWillResignActive:(UIApplication *)application { NSCalendar *gregorian = [[NSCalendar alloc]…
Ranjit
  • 4,576
  • 11
  • 62
  • 121
4
votes
2 answers

GMT timezone conversion in objective c

I am trying to convert nsstring to nsdate and then to the systemtimezone. Is my code right? Any help appreciated. NSString *str=@"2012-01-15 06:27:42"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [NSDateFormatter…
stefanosn
  • 3,264
  • 10
  • 53
  • 79
4
votes
1 answer

iPhone - How to get time zone offset?

We have NSTimeZone class that tells more about the time zone. But I want to get only the offset of the time. For example: +05.30 is offset for Inida In other words offset of time with reference to UTC. One problem with following code is that it…
Satyam
  • 15,493
  • 31
  • 131
  • 244
4
votes
1 answer

How can I map tz database names to city and country names?

Is there a publicly available mapping from tz database (aka zoneinfo database, aka Olson database) IDs to city and country? For example: "Pacific/Auckland" => "Auckland, New Zealand" "Europe/Copenhagen" => "Copenhagen, Denmark" "Europe/Paris" =>…
Simon Cave
  • 3,971
  • 4
  • 24
  • 28
4
votes
2 answers

IOS Time zone abbreviation without GMT offset. Need directly like IST,EST etc

NSTimeZone *timezone = [NSTimeZone systemTimeZone]; NSString *timeZoneAbberivation = [timezone abbreviation]; timeZoneAbberivation is printing like GMT+5:30 like that. But I need GMT+5:30 to be printed as IST. (IST is of India/Kolkatta). Suppose…
4
votes
1 answer

How to get current date in swift 3?

I want to get current date and time zone of user in Swift 3. I tried in Swift 2.2 following code : static var localTimeZoneAbbreviation: String { return NSTimeZone.localTimeZone().abbreviation!}
Mohsin Qureshi
  • 1,203
  • 2
  • 16
  • 26
1
2
3
16 17