// Instantiate an NSDateFormatter object NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; // you can set the time format as needed [dateFormatter setDateFormat: @ "yyyy-MM-dd HH: mm: ss"]; // use [NSDate date] to obtain the current system time NSString * currentDateStr = [dateFormatter stringFromDate: [NSDate date]; // output format: 10:22:13 NSLog (@ "% @", currentDateStr ); // do not forget to release [dateFormatter release] for unused objects after alloc; // obtain the current day of the week based on the time string ---(voi D) GetTime {// convert the string to a time format for parsing NSString * string = "; NSDateFormatter * inputFormatter = [[[NSDateFormatter alloc] init] autorelease]; [inputFormatter setDateFormat: @ "yyyy-MM-dd HH: mm"]; NSDate * inputDate = [inputFormatter dateFromString: string]; NSCalendar * calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar] autorelease]; NSDateComponents * comps = [[[NSDateComponents alloc] init] autorelease]; NSInteger unitFlags = bytes | NSDayCalendarUnit | percent | NSSecondCalendarUnit; comps = [calendar components: unitFlags fromDate: inputDate]; int week = [comps weekday]; NSString * strWeek = [self getweek: week]; self. textfield. text = strWeek; NSLog (@ "week is: % @", StrWeek);}-(NSString *) getweek :( NSInteger) week {NSString * weekStr = nil; if (week = 1) {weekStr = @ "Sunday ";} else if (week = 2) {weekStr = @ "Monday";} else if (week = 3) {weekStr = @ "Tuesday ";} else if (week = 4) {weekStr = @ "weekStr";} else if (week = 5) {weekStr = @ "Thursday ";} else if (week = 6) {weekStr = @ "Friday";} else if (week = 7) {weekStr = @ "Saturday";} return weekStr ;} description of various time characters. In some region settings, you can use other characters to represent time delimiters. The time Delimiter is formatted every hour, minute, and second. The actual characters used as time delimiters In the formatted output are determined by the current regional value of your application. (/) Date separator. In some region settings, you can use other characters to represent the date separator. The date Delimiter is used to format the date value every day, month, and year. The actual Characters Used as the date Separator in the formatting output are determined by the current culture of your application. (%) Indicates that subsequent characters should be read in single-letter format regardless of the trailing letter. It is also used to indicate that the single letter format should be read in the User-Defined Format. For more details, see the following content. D. display the day as a number without leading zero (for example, 1 ). If this is a unique character in the User-Defined number format, use % d. Dd displays the day as a number with a leading zero (for example, 01 ). EEE displays the day as an abbreviation (for example, Sun ). EEEE displays the day as the full name (for example, Sunday ). M Displays the month as a number without leading zero (for example, January 1, January ). If this is a unique character in the User-Defined number format, use % M. MM displays the month as a number with a leading zero (for example, 01/12/01 ). MMM displays the month as an abbreviation (for example, Jan ). MMMM displays the month as the complete month name (for example, January ). Gg display time/epoch string (for example, A. D.) h uses the 12-hour system to display the hour as A number without leading zero (for example, 1:15:15 ). If this is a unique character in the User-Defined number format, use % h. Hh uses the 12-hour system to display the hour as a number with a leading zero (for example, 01:15:15 ). H uses the 24-hour system to display the hour as a number without leading zero (for example, 1:15:15 ). If this is a unique character in the User-Defined number format, use % H. HH uses the 24-hour system to display the hour as a number with a leading zero (for example, 01:15:15 ). M Displays the minute as a number without leading zero (for example ). If this is a unique character in the User-Defined number format, use % m. Mm displays the minute as a number with a leading zero (for example, 12:01:15 ). S displays the second as a number without leading zero (for example ). If this is a unique character in the User-Defined number format, use % s. Ss displays seconds as numbers with leading zeros (for example, 12:15:05 ). F displays the fractional part of the second. For example, ff is precisely displayed to 1% seconds, while ffff is precisely displayed to one in ten seconds. Up to seven f characters can be used in a user-defined format. If this is a unique character in the User-Defined number format, use % f. T uses the 12-hour format, and displays uppercase A for any hour before noon, and uppercase P for any hour between noon and p.m. If this is a unique character in the User-Defined number format, use % t. Tt uses the 12-hour region settings to display an uppercase AM for any hour before noon and an uppercase PM for any hour between noon and p.m. For regions in the 24-hour format, no characters are displayed. Y displays the year (0-9) as a number without leading zero. If this is a unique character in the User-Defined number format, use % y. Yy displays the year in the format of two digits with leading zeros (if applicable ). Yyy displays the year in four-digit format. Yyyy displays the year in four-digit format. Z shows the time zone offset without leading zero (for example,-8 ). If this is a unique character in the User-Defined number format, use % z. Zz displays the time zone offset with leading zero (for example,-08) zzz displays the complete time zone offset (for example) format: M/d/yy 12/7/58 d-MMM 7-Dec d-MMMM-yy 7-December-58 d MMMM 7 December MMMM yy December 58 hh: mm tt h: mm: ss t 8:50:35 p h: mm 20:50 H: mm: ss 20:50:35 M/d/yyyy H: mm 12/7/1958 20:50