nsdate

how to get start and end time of today's date in ios? [duplicate]

一笑奈何 提交于 2019-12-05 03:34:14
This question already has answers here : NSDate beginning of day and end of day (21 answers) Closed 3 years ago . I am getting current date and time by using this code let today: NSDate = NSDate() let dateFormatter: NSDateFormatter = NSDateFormatter() dateFormatter.timeStyle = NSDateFormatterStyle.MediumStyle dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" dateFormatter.timeZone = NSTimeZone(abbreviation: "SGT"); print(dateFormatter.stringFromDate(today)) but i want to get start time and end time of today’s date example : 12-09-2016 00:00:00 AND 12-09-2016 23:59:59 How to get start and end

NSDate for “beginning of next hour”

↘锁芯ラ 提交于 2019-12-05 02:15:31
问题 I'd like to make a countdown to the next full hour. It's pretty easy to countdown to a specific time, like: NSDate *midnight = [NSDate dateWithNaturalLanguageString:@"midnight tomorrow"]; how do I define an NSDate for "the beginning of every hour"? Thanks! EDIT: This is what I have currently. Having trouble integrating the solutions in to my code. Any help would be greatly appreciated. :) -(void)updateLabel { NSDate *now = [NSDate date]; NSDate *midnight = [NSDate

iOS create date in the future ignoring daylight savings

梦想与她 提交于 2019-12-05 01:42:41
I'm trying to work with dates and create dates in the future, but daylight savings keeps getting in the way and messing up my times. Here is my code to move to midnight of the first day of the next month for a date: + (NSDate *)firstDayOfNextMonthForDate:(NSDate*)date { NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; calendar.timeZone = [NSTimeZone systemTimeZone]; calendar.locale = [NSLocale currentLocale]; NSDate *currentDate = [NSDate dateByAddingMonths:1 toDate:date]; NSDateComponents *components = [calendar components:NSYearCalendarUnit |

change NSDate from one time zone to another [closed]

青春壹個敷衍的年華 提交于 2019-12-04 23:20:07
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 6 years ago . Given a date in NSString like "2012-12-17 04:36:25" (which is GMT) how one can simply change it to other time zones like EST, CST All the steps I saw so far took so many unnecessary steps Inder Kumar Rathore NSString *str = @"2012-12-17

WKInterfaceTimer used as a timer to countdown start and stop

别来无恙 提交于 2019-12-04 20:46:43
问题 I am trying to create a timer to countdown x minutes and y seconds. I am computing the number of seconds and creating the InterfaceTimer like this: timer.setDate(NSDate(timeIntervalSinceNow:Double(secondsValue+1))) timer.stop() after that I keep stoping it and starting it again and again, but the values are suddenly decreasing as "time(now) doesn't stop". Eg: if the timer shows :55, I start it for 3sec and stop it, it shows :52, I wait 10seconds and then start it again, it starts from :42. I

find total number of days between two dates in iphone

雨燕双飞 提交于 2019-12-04 20:41:20
问题 I would like to find total number of days between two dates. e.g. today is 01-01-2011(DD-MM-YYYY) and second date is (25-03-2011), how would I find the total number of days? NSDate *currentdate=[NSDate date]; NSLog(@"curretdate is ==%@",currentdate); NSDateFormatter *tempFormatter1 = [[[NSDateFormatter alloc]init]autorelease]; [tempFormatter1 setDateFormat:@"dd-mm-YYYY hh:mm:ss"]; NSDate *toDate = [tempFormatter1 dateFromString:@"20-04-2011 09:00:00"]; NSLog(@"toDate ==%@",toDate); 回答1: In

Sorting array based on date and time with two dictionary keys

空扰寡人 提交于 2019-12-04 19:45:47
I am trying to sort an array based on date and time , I can successfully sort the array based on date both time is coming as another value in dictionary. So date comes as a string in format "yyyy-MM-dd" and time comes in as a string in format "HH:mm" Time value comes in key "starts" as string '"HH:mm"' format. I know somehow I need to combine two strings to 'yyyy-MM-dd HH:mm' but how? -(NSMutableArray *)sortArrayBasedOndate:(NSMutableArray *)arraytoSort { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd"]; NSComparator compareDates = ^(id

Swift 2 for loop low and high date between

…衆ロ難τιáo~ 提交于 2019-12-04 19:37:33
I have Array ; var mydates : [String] = [] let startDate = "2018-03-01" let endDate = "2018-03-03" And I have 3 variable , startDate , endDate , dates , i want to append that variables, like; if startDate = 2018-03-01, and endDate = 2018-03-03 will be add dates variable inside = "2018-03-01,2018-03-02,2018-03-03" between all dates from start and end dates. How can i do it in swift 2 any idea ? Here is Solution for Print all dates between two Date (Swift 4 Code) var mydates : [String] = [] let startDate = "2018-03-01" let endDate = "2018-03-05" var dateFrom = Date() // First date var dateTo =

Swift - Check if date is in next week / month. ( isDateInNextWeek() isDateInNextMonth() )

不想你离开。 提交于 2019-12-04 19:32:21
We have those convenient functions in calendar: let calendar = NSCalendar.currentCalendar() calendar.isDateInToday(date) calendar.isDateInTomorrow(date) But I am missing those two: calendar.isDateInNextWeek(date) calendar.isDateInNextMonth(date) As @Rob mentioned, the meaning is: "in the calendar week starting this coming Sunday, going through the following Saturday" I having a hard time figuring out how to implement those functions in a robust way that covers all the corner cases. Can someone provide an assistant? The algorithm is not very spectacular: Calculate start of current week Use

How to calculate time difference in minutes between two dates in iOS [duplicate]

末鹿安然 提交于 2019-12-04 19:27:03
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How to calculate time in hours between two dates in iOS I am beginner to Objective-C, so I need your help in syntax making. My problem goes like this: I have 2 Strings, and I want to convert that into NSDate and then calculate the time difference between the dates in minutes. How can I do this? 回答1: Use NSDateFormatter to convert the date strings into NSDate objects. Call -[NSDate timeIntervalSinceDate:] to get