Question: I have a bunch of different show times in a database and want to display the correct time based on the users time zone by creating an offset.

I'm getting the users time zone offset from GMT and converting that to hours first.

```
NSTimeZone.localTimeZone().secondsFromGMT / 60 / 60

```

Then I need to find a way to add the hours to the date object.. that is where I/m struggling.

```
let formatter = NSDateFormatter()
    formatter.dateFormat = "HH:mm"

    let date = formatter.dateFromString(timeAsString)
    println("date: \(date!)")

```

Then I'm creating a string from the date to use in a label, to have it easy to read with the AM / PM.

```
    formatter.dateFormat = "H:mm"
    formatter.timeStyle = .ShortStyle
    let formattedDateString = formatter.stringFromDate(date!)
    println("formattedDateString: \(formattedDateString)")

```

I just can't seem to find out how to add/subtract hours. I've split the string up but it sometimes goes negative and won't work. Maybe I'm going about this wrong.

Thanks for any help.

Keith

Answer: 
I would use the [dateByAddingTimeInterval](https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/index.html%23//apple_ref/occ/instm/NSDate/dateByAddingTimeInterval:) function to add and subtract hours. Add a to the dateFormat string to print am or pm.

```
var showTimeStr = "00:00 PM" //show time in GMT as String
let formatter = NSDateFormatter()
formatter.dateFormat = "hh:mm a"
let showTime = formatter.dateFromString(showTimeStr)
showTime.dateByAddingTimeInterval(3600) //Add number of hours in seconds, subtract to take away time
showTimeStr = formatter.stringFromDate(showTime)

```
Here is my final code, combined with b.Morgans answer. I believe it's all working now.

```
let offsetTime = NSTimeInterval(NSTimeZone.localTimeZone().secondsFromGMT)

var showTimeStr = "05:00 PM" //show time in GMT as String
let formatter = NSDateFormatter()
formatter.dateFormat = "h:mm a"
let showTime = formatter.dateFromString(showTimeStr)
let finalTime = showTime?.dateByAddingTimeInterval(offsetTime) //Add number of hours in seconds, subtract to take away time
showTimeStr = formatter.stringFromDate(finalTime!)

```