nsdate

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

淺唱寂寞╮ 提交于 2020-01-07 09:43:48
问题 I tried something like this: var calendar = Calendar.current var dayFutureComponents = DateComponents() dayFutureComponents.day = 1 // aka 1 day var d = calendar.date(byAdding: dayFutureComponents, to: Date()) ...//setting of d.hour, d.minute, d.second to zero and finding the difference between 2 dates The problem is for example my current GMT is +3 . So the result differs from one I need to achieve by 3 hours. How to fix this issue? 回答1: First create a Calendar for the UTC timezone. Second

Need assistance regarding NSDateFormatter

怎甘沉沦 提交于 2020-01-07 09:28:55
问题 I only want date like "29-10-2014" with no time so i did this NSDateFormatter *df = [[NSDateFormatter alloc]init]; [df setDateFormat:@"dd-MM-yyyy"]; NSString *sDate = [df stringFromDate:date]; If I log the sDate I am getting perfect result. But I dont want NSString I want date object, to do that here what I did is NSDate *theDate = [df dateFromString:sDate]; Now I am getting 2014-10-29 19:00:00 +0000 I only want 29-10-2014 . 回答1: This is because -[NSDate description] returns you full

NSDate's initWithString: is returning nil

眉间皱痕 提交于 2020-01-07 04:32:14
问题 I'm using Stig Brautaset's JSON framework serialize some objects, including NSDates (which are not directly supported). I decided to use NSDate's description as the JSONFragment representation of a date (I don't care about the minor loss of precision incurred in doing so). To extend Stig Brautaset's JSON framework to include NSDates, I defined a category: @interface NSDate (NSDate_JSON) <JSONInitializer> -(NSString *) JSONFragment; @end To recreate an NSDate (and other classes) from JSON, I

(Swift) Setting UIDatePicker View from User Input

微笑、不失礼 提交于 2020-01-07 03:01:30
问题 First I display a UIDatePicker on the screen and allow the user to choose a date and time. I save that value like this, which gets a date format that looks like this: 6/1/16, 1:47 PM let time = NSDateFormatter.localizedStringFromDate(datePicker.date, dateStyle: .ShortStyle, timeStyle: .ShortStyle) Later on in the application, I want users to be able to edit their original date, so when a button is pressed, I would like the UIDatePicker to display the time that they had originally chosen. I am

Calculating StartDate and endDate of a day based on todays date. Swift 2

拜拜、爱过 提交于 2020-01-07 02:35:30
问题 I have the following function which i am using to calculate a start and end of todays date. It was working perfectly last week, i think it may have something to do with the clocks going forwards? func rangeOfPeriod(period: NSCalendarUnit, date: NSDate) -> (NSDate, NSDate) { let calendar = NSCalendar.currentCalendar() var startDate: NSDate? = nil var duration: NSTimeInterval = 0 calendar.rangeOfUnit(period, startDate: &startDate, interval: &duration, forDate: date) let endDate = startDate!

Reorder dynamic UITableView by NSDate

我只是一个虾纸丫 提交于 2020-01-06 23:50:23
问题 In my app I have a UITableView which will be fill with core date items. As you can see in this post, I have already asked for a sorting function: https://stackoverflow.com/a/36703648/6012187 func ReSort() { CoreDataItems.sortInPlace({sortAscending ? $0.RowName < $1.RowName : $0.RowName > $1.RowName}) sortAscending = !sortAscending tableView.reloadData() } Now my question is, how can I set dynamically the RowName Value? for example. I save the the RowName in the user defaults. but $0.defaults

How to offset NSDate with UTC timezone offset without hardcoded manual calculation

。_饼干妹妹 提交于 2020-01-06 21:06:01
问题 Imagine the current local time being 15:11 UTC. I retrieve a data set from the server showing the opening closing time of a business displayed like so: { close = { day = 3; time = 0200; }; open = { day = 2; time = 1700; }; I also receive a utc-offset property exposed like so: "utc_offset" = "-420”; which I imagine is a minute offset giving an hour offset of 7 hours which seems right considering the timezone I'm in is UTC and the business location's opening hours information I'm receiving is

How to offset NSDate with UTC timezone offset without hardcoded manual calculation

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-06 21:04:20
问题 Imagine the current local time being 15:11 UTC. I retrieve a data set from the server showing the opening closing time of a business displayed like so: { close = { day = 3; time = 0200; }; open = { day = 2; time = 1700; }; I also receive a utc-offset property exposed like so: "utc_offset" = "-420”; which I imagine is a minute offset giving an hour offset of 7 hours which seems right considering the timezone I'm in is UTC and the business location's opening hours information I'm receiving is

How to check NSDate against a date in TAPKU calendar

北慕城南 提交于 2020-01-06 16:52:12
问题 I am using core data to store objects for my project.There is a date field in the object .I want to check against the clicked date of the Tapku calendar component for iphone. The date on my object is in the format 2011-01-10 and it is a localized date . How can i check the date against the date returned from the tapku calendar control. 回答1: Yes you can, here is what I did to make it work: on the method: (NSArray*)calendarMonthView:(TKCalendarMonthView *)monthView marksFromDate:(NSDate *

how to compare time with current date and time?

人走茶凉 提交于 2020-01-06 08:58:07
问题 In My application I have to complete a particular task in given time.So first i calculated the time complete the task in seconds and then add that time to the current that like this. NSDate *mydate = [NSDate date]; NSTimeInterval TotalDuraionInSec = sec.cal_time * 60; TaskCmpltTime = [mydate addTimeInterval:TotalDuraionInSec]; NSLog(@"task will be completed at%@",TaskCmpltTime); now I compare time like this if([CurrentTime isEqualToDate:AfterCmpltTime]){ NSLog (@"Time Finish"); } but I want