Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 03-25-2009, 03:02 PM   #3 (permalink)
Scenario
Registered Member
 
Join Date: Jul 2008
Posts: 13
Scenario is on a distinguished road
Default Refined

Here's a more elegant solution without all the parsing and with only a single method call:

Code:
+ (NSDate *)dateWithSQLString:(NSString *)string {
	NSDate *date = [NSDate dateWithNaturalLanguageString:string];
	if (!date) return nil;
	NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease];
	[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
	NSDateComponents *components = [calendar components:(
		NSYearCalendarUnit |
		NSMonthCalendarUnit |
		NSDayCalendarUnit |
		NSHourCalendarUnit |
		NSMinuteCalendarUnit |
		NSSecondCalendarUnit)
		fromDate:date];
	[calendar setTimeZone:[NSTimeZone defaultTimeZone]];
	date = [calendar dateFromComponents:components];
	return date;
}

Last edited by Scenario; 03-25-2009 at 03:09 PM.
Scenario is offline   Reply With Quote
 

» Advertisements
» Stats
Members: 175,631
Threads: 94,089
Posts: 402,802
Top Poster: BrianSlick (7,990)
Welcome to our newest member, hanhaursh7
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.