从整数组装日期对象? [英] Assemble date object from integers?

查看:79
本文介绍了从整数组装日期对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出三个分别代表日,月和年的整数,用什么代码将这些整数组合成一个日期对象?

Given three integers, representing a day, month and year, what code would assemble those integers into a date object?

推荐答案

您应该查看NSDateComponents:

int y = 2011;
int m = 1;
int d = 15;


NSDateComponents *dc = [[NSDateComponents alloc] init];
[dc setYear:y];
[dc setMonth:m];
[dc setDay:d];

NSLog(@"%@: %@", [[dc date] class], [dc date]);

这篇关于从整数组装日期对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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