Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given year, month and day, all in int, how would I generate an NSDate

Tags:

cocoa

nsdate

I think the solution is really simple, I just haven't come across it online.

Suppose I am given int year, int month, int day, int hour, int min, int sec.. how do I generate NSDate out of it?

I know we can use [NSDate initWithString:] but I think it gets complicated if month/day/hour/min/sec are one digit numbers.

like image 202
BU. Avatar asked Mar 16 '10 04:03

BU.


1 Answers

Suppose I am given int year, int month, int day, int hour, int min, int sec.. how do I generate NSDate out of it?

Put the ints into an NSDateComponents object, then ask an NSCalendar object to change that into a date.

like image 138
Peter Hosey Avatar answered Nov 09 '22 02:11

Peter Hosey