nsdate

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

三世轮回 提交于 2019-12-22 04:01:43
问题 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

iOS create date in the future ignoring daylight savings

荒凉一梦 提交于 2019-12-22 03:52:10
问题 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

iOS create date in the future ignoring daylight savings

江枫思渺然 提交于 2019-12-22 03:52:10
问题 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

How to use NSDate formatter with an array of dates?

☆樱花仙子☆ 提交于 2019-12-22 01:07:40
问题 I'm trying to generate an array of 30 days from the current date and put them into an array formatted correctly. I currently have a working generater to get 30 days from the current date and put it into an array but I don't know how to use NSDate formatter for an array. I know how to use the formatter for a single item but how can I format all the dates in my array? The format that I would like is (Month Day). Here's my code: NSMutableArray* dates = [[NSMutableArray alloc] init]; int

Date is getting changed while converting to NSDate from NSString

一曲冷凌霜 提交于 2019-12-22 00:09:34
问题 I am converting NSString to NSDate with help of NSDateFormatter. Now code works fine here in all OS with device & simulator but it is creating different Output at UK, USA region. Here is the code that I am using. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *dateString=[NSString stringWithString:@"2010-09-05 04:00:00"]; NSDate *dateObj = [dateFormatter dateFromString:dateString]; Actual date is : 2010-09-05 04

Swift 2 for loop low and high date between

痞子三分冷 提交于 2019-12-22 00:00:07
问题 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 ? 回答1: Here is Solution for Print all dates between two Date (Swift 4 Code) var mydates : [String] = [

How to write NSData to a new file in Swift?

允我心安 提交于 2019-12-21 20:45:10
问题 I am working to get the contents of an NSData instance written to a file. I am currently using an Xcode playground. This is my code: let validDictionary = [ "numericalValue": 1, "stringValue": "JSON", "arrayValue": [0, 1, 2, 3, 4, 5] ] let rawData: NSData! if NSJSONSerialization.isValidJSONObject(validDictionary) { do { rawData = try NSJSONSerialization.dataWithJSONObject(validDictionary, options: .PrettyPrinted) try rawData.writeToFile("newdata.json", options: .DataWritingAtomic) } catch { /

How to get dates of current month in Objective c?

浪尽此生 提交于 2019-12-21 20:19:38
问题 I am developing a app which uses the date, month, year. I want the current month dates,because current month can have 28,29,30,31 days. I have tried to get current year months. but i don't know the code for above. here is my code. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate *today = [NSDate date]; NSCalendar *currentCalendar = [NSCalendar currentCalendar]; NSDateComponents *yearComponents = [currentCalendar components:NSYearCalendarUnit fromDate:today]; int

Comparing NSDate

牧云@^-^@ 提交于 2019-12-21 19:49:04
问题 I would like to compare two NSDates however every date shows as being "Earlier" than todaysDate . Any ideas? let compareResult = self.todaysDate.compare(self.date) if compareResult == NSComparisonResult.OrderedDescending { println("Today is later than date2") } else { println("Future") } To get "todaysDate" let todaysDate = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute | .CalendarUnitMonth | .CalendarUnitYear

Using NSDate within an NSPredicate

送分小仙女□ 提交于 2019-12-21 12:49:14
问题 Is there a particular way to configure an NSPredicate to compare dates? Essentially I have a Photo object that has an NSDate, lastViewed. I'd like to configure an NSPredicate that will return all the Photo objects that have been viewed more recently than a specified time period - typically two days. I'm obtaining the past date like so: NSTimeInterval secondsPast = -172800; NSDate * twoDaysPast = [NSDate dateWithTimeInterval:secondsPast sinceDate:[NSDate date]]; And configuring the NSPredicate