获取当前系统时间? [英] Get current system time?

查看:104
本文介绍了获取当前系统时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Objective-C获取当前时间(HH:MM:SS)的最佳方法是什么。我想我应该看看NSDate& NSDateFormatter。我快速浏览了文档,它看起来比我预想的更复杂,所以我想我会检查这里,以确保我在正确的轨道。

Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would guess I should be looking at NSDate & NSDateFormatter. I had a quick glance at the docs and it looked a little more convoluted than I expected, so I thought I would check here to make sure I was on the right track.

gary

推荐答案

NSDate * now = [NSDate date];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm:ss"];
NSString *newDateString = [outputFormatter stringFromDate:now];
NSLog(@"newDateString %@", newDateString);
[outputFormatter release];

这篇关于获取当前系统时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆