Tuesday, August 28, 2012

Getting Current Date into a String (ios)


Hi Lets see the simple code to get current time


  //Get current date
    NSDate *date = [NSDate date];
    // format it
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init];
    [dateFormat setDateFormat:@"MMM dd, yyyy"];
    // convert it to a string
    NSString *dateString = [dateFormat stringFromDate:date];
    // free up memory
    [dateFormat release];
  //Try it
    NSLog(@"Todays date is = %@",dateString);
This is what i got :
Todays date is = Aug 28, 2012

Cheers

1 comment:

  1. Thanks for sharing your info. I truly appreciate your efforts and I will be waiting for your next write ups thanks once again.
    android mobile app development services in Sahiwal

    ReplyDelete