I am sorry, as this question may have been asked before, but I could not find an answer that worked in my situation.
I am new to Objective-C, and I am not entirely knowledgable, so I apologize beforehand in the case that I seem like I am not amazing 😉
So, I have a webView, and everyday, the url changes. Ex: on April 30th the url is http://example.com/mylinkApr30
Using dates, I made a variable (sorry if my terminology is off :\ ), and the url ends in %d everything works just fine, except when it comes to month. The months are not in the typical MM form, they are in a shortened text, with the three first letters of the month name. Ex: Jan, Feb, Mar, Apr, etc.
I have the month integer working, and it writes as 1,2,3 etc.
How should I go about changing that to Jan, Feb, Mar?
Is there a different way I could go about this??
I can confirm the days are working, I have tested it with having 1 variable, and using Apr at the end of the link.
Here is my code, so it is easier for you to understand what I am asking.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Balmoral";
NSCalendar *calendar= [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSCalendarUnit unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit |
NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |
NSSecondCalendarUnit;
NSDate *date = [NSDate date];
NSDateComponents *dateComponents = [calendar components:unitFlags fromDate:date];
//NSInteger year = [dateComponents year];
NSInteger month = [dateComponents month];
NSInteger day = [dateComponents day];
//NSInteger hour = [dateComponents hour];
//NSInteger minute = [dateComponents minute];
//NSInteger second = [dateComponents second];
NSString *baseURLStr = @"http://wwww.WebsiteHere.com/Apr";
NSURL *url = [NSURL URLWithString:[baseURLStr stringByAppendingFormat:@"%d.ashx", day]];
[webView loadRequest:[NSURLRequest requestWithURL:url]];
[NSCalendar release];
}
Check out the
NSDateFormatterclass, something like:monthString should be “Mar”