如何使用 NSDateFormatter 获取仅经过小时和分钟的完整时间戳?
我认为这只是一个小问题。搜索了一段时间后我仍然无法弄清楚。希望你能。 :-)
我想获得今天的完整时间戳,包括自己的小时和分钟。 我的方法如下(例如 dateStr 是 @"11:30"):
NSDateFormatter *myFormatter = [[[NSDateFormatter alloc] init] autorelease];
[myFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[myFormatter setDateFormat:@"HH:mm"];
NSDate *tmpDate = [myFormatter dateFromString:dateStr];
[myFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
...???
所以现在我得到
1970-01-01 11:30:00 +0000
我必须做什么才能将 dateStyle 应用于我的 NSDate 并获得今天的正确日期? 我知道我可以使用 [NSDate date]
来获取实际日期,但我可以做什么来“操纵”分钟和小时?
如果能从你们那里得到一些帮助,那就太好了:)
I think this is just a minor problem. After searching for some time I still can't figure it out. Hopefully you can. :-)
I want to get a full timestamp of today, passing own hours and minutes.
My approach was the following(dateStr is @"11:30" for example):
NSDateFormatter *myFormatter = [[[NSDateFormatter alloc] init] autorelease];
[myFormatter setTimeZone:[NSTimeZone systemTimeZone]];
[myFormatter setDateFormat:@"HH:mm"];
NSDate *tmpDate = [myFormatter dateFromString:dateStr];
[myFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZ"];
...???
So now I get
1970-01-01 11:30:00 +0000
What do I habe to do to apply the dateStyle to my NSDate and get the correct date of today?
I know that I can use [NSDate date]
to get the actual date but what can I do to "manipulate" only minutes and hours?
Would be great to get some help from you guys :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)