I want current time in following format in a string.
dd-mm-yyyy HH:MM
How?
Just 3 steps. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; Set the date format in which you want your string.
NSDate and NSDateFormatter classes provide the features of date and time. NSDateFormatter is the helper class that enables easy conversion of NSDate to NSString and vice versa. A simple example to show conversion of NSDate to NSString and back to NSDate is shown below.
You can use %@ for all objects including NSString. This will in turn call the objects description method and print the appropriate string.
int len = [myString length];
You want a date formatter. Here's an example:
NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-yyyy HH:mm"]; NSDate *currentDate = [NSDate date]; NSString *dateString = [formatter stringFromDate:currentDate];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With