Re: Times in other cities
Re: Times in other cities
- Subject: Re: Times in other cities
- From: "Eric E. Dolecki" <email@hidden>
- Date: Mon, 15 May 2017 12:50:57 +0000
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 <email@hidden> wrote:
>
> > On May 14, 2017, at 5:47 PM, Eric Dolecki <email@hidden> 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 (email@hidden)
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:
This email sent to email@hidden