View Full Version : Urgent: Get Current Time
ilx.mac
Jul 23, 2009, 09:36 AM
Hi there,
I need to get the current time in the format HH:MM:SS AM/PM. I have the date in textfield1.text. I tried using NDDate. But could not get the expected.
Can some one help me ?
Thanks in Advance!:)
Guiyon
Jul 23, 2009, 09:57 AM
Take a look at the NSDate method:- (NSString *)descriptionWithCalendarFormat:(NSString *)formatString timeZone:(NSTimeZone *)aTimeZone locale:(id)localeDictionary and read through Converting Dates to Strings (http://developer.apple.com/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtDatesToStrings.html#//apple_ref/doc/uid/20000187)
kainjow
Jul 23, 2009, 11:20 AM
Take a look at the NSDate method:- (NSString *)descriptionWithCalendarFormat:(NSString *)formatString timeZone:(NSTimeZone *)aTimeZone locale:(id)localeDictionary and read through Converting Dates to Strings (http://developer.apple.com/documentation/Cocoa/Conceptual/DatesAndTimes/Articles/dtDatesToStrings.html#//apple_ref/doc/uid/20000187)
Unfortunately it appears that method isn't available on the iPhone (at least from a quick glance at the documentation).
I think the recommended route is to use NSCalendar with NSDateComponents, or NSDateFormatter.
Guiyon
Jul 23, 2009, 12:02 PM
Oops, had the wrong documentation pulled up. Since that method isn't available, it looks like Kainjow's suggestion is the best way to go.
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.