nstimeinterval

How to convert NSTimeInterval to int?

寵の児 提交于 2019-12-30 05:32:05
问题 How do I convert NSTimeInterval into an Integer value? My TimeInterval holds the value 83.01837 . I need to convert it into 83 . I have googled but couldn't find any help. 回答1: Direct assignment: NSTimeInterval interval = 1002343.5432542; NSInteger time = interval; //time is now equal to 1002343 NSTimeInterval is a double, so if you assign it directly to a NSInteger (or int, if you wish) it'll work. This will cut off the time to the nearest second. If you wish to round to the nearest second

swift : get the closest date stored in the core data

跟風遠走 提交于 2019-12-25 14:32:09
问题 I have two data in core data. Entity Name = "Contact", Attribute Name = "date"(selected datePicker.date), "content"(textFeild.text) It is that sort of information in a table view, was a success. I want to show only one content in the another view controller. The data of the closest time to the current time. I was asked to help with the following code. var stores: Contact? if ((stores?.date!.timeIntervalsince1970 ?? 0) > NSDate().timeIntervalSince1970) { labelName.text = stores?.content! } But

Is this method going to always give me 12:00:00 of the current day in ios?

对着背影说爱祢 提交于 2019-12-25 01:27:46
问题 Yes, this is similar to NSDate beginning of day and end of day, but that topic does not discuss whether it works for all situations which is what I am asking here. That question dealt with not getting back the correct value because they forgot NSDayCalendarUnit. This question is dealing with the accuracy of the value which as it turns out is not going to work with DST as I had suspected. In several parts of my app, I have the need to specify a time of day without caring about the actual day,

How to convert DispatchTimeInterval to NSTimeInterval (or Double)?

佐手、 提交于 2019-12-23 17:38:35
问题 I need to subtract a DispatchTimeInterval from an NSTimeInterval (or Double ). Is there a standard way to convert a DispatchTimeInterval to an NSTimeInterval ? 回答1: DispatchTimeInterval is a enum: public enum DispatchTimeInterval : Equatable { case seconds(Int) case milliseconds(Int) case microseconds(Int) case nanoseconds(Int) case never } You can initialize DispatchTimeInterval using: let tenSeconds: DispatchTimeInterval = .seconds(10) let tenNanoseconds: DispatchTimeInterval = .nanoseconds

Actually using UIDatePickerModeCountDownTimer as a timer

时光毁灭记忆、已成空白 提交于 2019-12-22 12:14:48
问题 I am just trying to make a timer. I would like to use UIDatePickerModeCountDownTimer mode of the UIDatePicker , so that when the user simply selects say 15 mins in the picker, they are passed back to a screen that shows the value of 15 mins in a label that they can then count down from. As I have tried to get the value from the DatePicker, I realized that the picker passes back an NSTimeInterval that gets the current time in seconds: UIDatePicker *pickerView = [[UIDatePicker alloc] init];

calculating 'timeIntervalSinceNow' with a negative value (CLLocation example)?

狂风中的少年 提交于 2019-12-22 09:19:48
问题 i don't understand this example from the doc : the timeIntervalSinceNow method should show a positive value, but how can we reach "5" as mentioned in the code? (i think it's either 0 more or less, or -10 , -20, -30 etc... but how can we get a positive value such as 5?) : - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation { // test the age of the location measurement to determine if the measurement is cached

Convert date to timestamp in iOS

女生的网名这么多〃 提交于 2019-12-19 09:57:26
问题 How do you convert any given date to milliseconds? For example, 2014-01-23 to timestamp conversion. NSDate *date = [dateFormatter dateFromString:@"2014-01-23"]; NSLog(@"date=%@",date); NSTimeInterval interval = [date timeIntervalSince1970]; NSLog(@"interval=%f",interval); NSDate *methodStart = [NSDate dateWithTimeIntervalSince1970:interval]; [dateFormatter setDateFormat:@"yyyy/mm/dd "]; NSLog(@"result: %@", [dateFormatter stringFromDate:methodStart]); Output result: 1970/30/01 回答1: Have it a

NSTimeInterval to unix timestamp

假装没事ソ 提交于 2019-12-19 03:07:19
问题 I'm getting CMDeviceMotion objects from CMMotionManager . One of the properties of the CMDeviceMotion is timestamp, which is expressed as a NSTimeInterval (double). This allows for "sub millisecond" timestamp precision, according to documentation. [motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion *motion, NSError *error) { NSLog(@"Sample: %d Timestamp: %f ",counter, motion.timestamp); } Unfortunately, NSTimeInterval is calculated since last device boot,

Find difference in seconds between NSDates as integer using Swift

元气小坏坏 提交于 2019-12-17 15:22:29
问题 I'm writing a piece of code where I want to time how long a button was held down. To do that I recorded an NSDate() when the button was pressed, and tried using the timeIntervalSinceDate function when the button was released. That seems to work but I can't find any way to print the result or switch it to an integer. var timeAtPress = NSDate() @IBAction func pressed(sender: AnyObject) { println("pressed") timeAtPress = NSDate() } @IBAction func released(sender: AnyObject) { println("released")

NSTimeInterval seems to be wrong for last day of the given month- iOS

↘锁芯ラ 提交于 2019-12-13 05:41:18
问题 In my local database, I have a list of NSTimeInterval values saved. I have to find out and fetch all records available in a given Month. The only problem is in fetching records for last day of the given month seems to be unavailable. Lets say given month is December so I have to fetch all the records from 1st Dec to 31st Dec (Till 11:59PM) I am using following implementation: [self.dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *startDate = [self.dateFormatter dateFromString:@"1-12-2012"]