Question: I'm trying to store today's date in a sqlite table as a string in a 24-hour time format regardless of the user's locale. Because NSDate honours the user's locale, this code returns different results depending on the user's location:

```
NSLog(@"The date is %@", [NSDate date]);

```

If their locale is set to the United Kingdom, where 24-hour time is the default, the above returns
'The date is 2009-09-05 11:17:35', whereas if they're in the United States, where 12-hour time is the default, it returns 'The date is 2009-09-05 11:17:35 AM'.

Is there a way to automatically detect and convert 12-hour time to 24-hour time before committing it to the database? I'm using SQLite Persistent Objects, so I need to provide the date as an NSDate and not NSString.

Answer: 
Update: in the end I chose to override the user's locale before manipulating the date and storing it, by using NSLocale. So, instead of this:

```
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSS"];  
NSString *formattedDateString = [dateFormatter stringFromDate:self];
```

I did this:

```
NSLocale *POSIXLocale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:POSIXLocale];  
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSSS"];  

NSString *formattedDateString = [dateFormatter stringFromDate:self];

```

This has the effect of standardising the date format before storing it. For those using sqlitepo who encounter the same issue, the relevant code to amend can be found in NSDate-SQLitePersistence.m on lines 33 and 46. 

Thanks to all who chipped in.
This looks like a bug in SQLite Persistent Objects. The library takes your NSDate instance and serialises it as a string in the format `@"yyyy-MM-dd HH:mm:ss.SSSS"`, which means that the timezone information is actually being thrown out. When the date string is converted back into an NSDate, the timezone is assumed to be the local time zone. This works only in the case that all your NSDate instances are in the local time zone.

The easiest way of fixing this is to patch the `NSDate(SqlPersistence)` category defined by SQLite Persistent Objects in `NSDate-SQLitePersistence.m` to include the timezone in the format string (e.g. `@"yyyy-MM-dd HH:mm:ss.SSSS Z"`) during serialisation and deserialisation. However, the proper fix would be to serialise the NSDate using the a DATETIME column rather than a char-based column. 

When you're displaying the dates in your UI, you can then use your own `NSDateFormatter` to define your own string date format.