使用Cocoa / objective-C从整数构建NSDate(年... ...) [英] Building NSDate from integers (year ... second) with Cocoa/objective-C

查看:117
本文介绍了使用Cocoa / objective-C从整数构建NSDate(年... ...)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有年,mont,...,第二个整数类型,我需要从他们构建NSDate。
我试过这个代码,但我有(null)。

I have year, mont, ... , second in integer type, and I need to build NSDate from them. I tried this code, but I got (null).

NSDateFormatter *tempFormatter = [[[NSDateFormatter alloc]init]autorelease];
[tempFormatter setDateFormat:@"yyyy-mm-dd hh:mm:ss"];
NSString* message = [NSString stringWithFormat:@"%04d-%02d-%02d %02d:%02d:%02d", year, month, day, hour, minute, second];
NSDate *day3 = [tempFormatter dateFromString:message];

此代码有什么问题?

推荐答案

而不是

[tempFormatter setDateFormat:@"yyyy-mm-dd hh:mm:ss"];

[tempFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

这篇关于使用Cocoa / objective-C从整数构建NSDate(年... ...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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