- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
- [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
- //[dateFormatter setDateFormat:@"hh:mm:ss"]
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS" ]; //毫秒
- NSLog(@"Date%@" , [dateFormatter stringFromDate:[NSDate date]]);
- [dateFormatter release];
Specifier | Description |
---|---|
| A |
| Abbreviated weekday name |
| Full weekday name |
| Abbreviated month name |
| Full month name |
| Shorthand for “ |
| Day of the month as a decimal number (01-31) |
| Same as |
| Milliseconds as a decimal number (000-999) |
| Hour based on a 24-hour clock as a decimal number (00-23) |
| Hour based on a 12-hour clock as a decimal number (01-12) |
| Day of the year as a decimal number (001-366) |
| Month as a decimal number (01-12) |
| Minute as a decimal number (00-59) |
| AM/PM designation for the locale |
| Second as a decimal number (00-59) |
| Weekday as a decimal number (0-6), where Sunday is 0 |
| Date using the date representation for the locale, including the time zone (produces different results from |
| Time using the time representation for the locale (produces different results from |
| Year without century (00-99) |
| Year with century (such as 1990) |
| Time zone name (such as Pacific Daylight Time; produces different results from |
| Time zone offset in hours and minutes from GMT (HHMM) |