The following should give me an NSDate object of 9:30
:
NSString *dateString = @"09-30";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh-mm"];
NSDate *dateFromString = [[NSDate alloc] init];
dateFromString = [dateFormatter dateFromString:dateString];
How do I get the current time in the same format?
By default, the date and time, visible on the Lock Screen, are set automatically based on your location. If you want to change them—for example, when you're traveling—you can adjust them. Go to Settings > General > Date & Time.
To insert the current time, press Ctrl+Shift+; (semi-colon). To insert the current date and time, press Ctrl+; (semi-colon), then press Space, and then press Ctrl+Shift+; (semi-colon).
Answer: A: Answer: A: Time is at the top left of your home screen, if your phone is locked, tap the home screen and it will display time and date.
NSDate *currentTime = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh-mm"];
NSString *resultString = [dateFormatter stringFromDate: currentTime];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"hh-mm"];
NSDate *currentDate = [NSDate date];
NSString *currentDateString = [dateFormatter 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