[Solved] Calculate time interval to 0.00 of the next day according to GMT in swift or objective-c?

First create a Calendar for the UTC timezone. Second get the startOfDay using the UTC calendar. Third add one day to that date. Then you can useDatemethodtimeIntervalSince(_ Date)` to calculate the amount of seconds between those two dates: extension Calendar { static let iso8601UTC: Calendar = { var calendar = Calendar(identifier: .iso8601) calendar.timeZone = TimeZone(identifier: … Read more

[Solved] NSDateFormatter returning nil with dateFromString

NSString *[email protected]”1992-11-15″; NSDateFormatter *format = [[NSDateFormatter alloc] init]; //Set your input format [format setDateFormat:@”yyyy-MM-dd”]; //Parse date from input format NSDate *dateOfBirth = [format dateFromString:trimmedDOB]; //Set your output format [format setDateFormat:@”MM-dd-yyyy”]; //Output date in output format NSLog(@”DATE IS %@”,[format stringFromDate:dateOfBirth]); 0 solved NSDateFormatter returning nil with dateFromString

[Solved] Getting the first date from what a user has selected

First you need to create an enumeration for the weekdays: extension Date { enum Weekday: Int { case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday } } Second create an extension to return the next weekday desired: extension Date { var weekday: Int { return Calendar.current.component(.weekday, from: self) } func following(_ weekday: Weekday) … Read more

[Solved] How to convert Objective-C to date format yyyy-MM-dd [duplicate]

Assuming it is a timestamp, you can do the following to convert it into a NSDate object: NSDate *date = [NSDate dateWithTimeIntervalSince1970:1460510348510/1000.0]; which prints out 2016-04-13 01:19:08 +0000 if you NSLog it. — How you can parse that response into an actual timestamp is described below: Parsing JSON (date) to Swift solved How to convert … Read more

[Solved] date not showing in correct manner

Try to change like this: In ViewDidload: firstdate = [[NSCalendar currentCalendar] dateByAddingUnit:NSCalendarUnitDay value:-6 toDate:[NSDate date] options:nil]; // And below method -(void)dateChange { NSArray *labelArray = @[flabel, slabel, tlabel, folabel, fivlabel,sixlabel,sevenlabel]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSCalendar *calendar = [NSCalendar currentCalendar]; dateFormatter.dateFormat = @”ddMMM”; for (NSInteger i = 0; i < 7; ++i) { NSDate … Read more

[Solved] Calculate next date in week

Use [NSCalendar currentCalendar] to get NSDateComponents from the current date, especially NSWeekdayCalendarUnit and NSWeekOfYearCalendarUnit. the components will have a member weekday, that ranges from 1 — sunday to 7 — saturday. if it is 1 or 2, create a new componets with weekday 2, if it is 7, add one to weekOfYear and set weekday … Read more