You might want to err on the side of caution and ensure that the Calendar 
object is explicitly set to Gregorian rather than using the current system 
setting.

Jonathan

> On 15 May 2017, at 13:50, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> Thanks for your reply. Does this look safe to use?
> 
> // London
> let locale = TimeZone.init(abbreviation: "BST")
> let cal = Calendar.current
> let date = Date()
> let comp = cal.dateComponents(in:locale!, from: date)
> 
> // Local (right now for me it's Boston)
> let hour = Calendar.current.component(.hour, from: date)
> 
> print("HOUR OFFSET: \(comp.hour! - hour)") //HOUR OFFSET: 5
> 
> It's okay if the modifier is negative (Los Angeles from Boston, etc.)
> 
> 
> 
> 
> 
> 
> On Sun, May 14, 2017 at 9:29 PM Jens Alfke <j...@mooseyard.com> wrote:
> 
>> 
>>> On May 14, 2017, at 5:47 PM, Eric Dolecki <edole...@gmail.com> wrote:
>>> 
>>> I have a clock. If like to present the times in a few major cities.  Say
>> London, England. Based on the user's current time zone, present the correct
>> hour, min, and second for London. If I can see how to do it for one city, I
>> should be good for others.
>> 
>> Get an NSTimeZone instance based on a GMT offset or a name
>> Create an NSDateFormatter and set its timeZone property.
>> Use the formatter to convert [NSDate date] to a string.
>> 
>> If you want to display the time in some other way, like an analog clock,
>> use NSDateComponents instead of NSDateFormatter; then you can get the
>> hours, minutes and seconds.
>> 
>> —Jens
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to