Jha*_*iya 16
要使用当前系统时间
NSDate* currentDate = [NSDate date];
并获取NSDate的字符串表示形式
- (NSString *)description
Run Code Online (Sandbox Code Playgroud)
然后在下面使用
NSString* dateInString = [currentDate description];
Run Code Online (Sandbox Code Playgroud)
小智 11
喜欢分享这个简单的代码示例.只需将其放在myClass代码中的任何位置即可.您可以找到更多格式示例> iPhone NSDateFormatter的格式字符串.
// Get current date time
NSDate *currentDateTime = [NSDate date];
// Instantiate a NSDateFormatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// Set the dateFormatter format
//[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
// or this format to show day of the week Sat,11-12-2011 23:27:09
[dateFormatter setDateFormat:@"EEE,MM-dd-yyyy HH:mm:ss"];
// Get the date time in NSString
NSString *dateInStringFormated = [dateFormatter stringFromDate:currentDateTime];
NSLog(@"%@", dateInStringFormated);
// Release the dateFormatter
[dateFormatter release];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24049 次 |
| 最近记录: |