nsdate

NSDate returns wrong date on the first of month

纵然是瞬间 提交于 2019-11-30 21:40:13
My app used [NSDate date ] function to get current date. Its work fine other days except 1st of every month during AM . i.e Follow Following steps : Set the system date as 01 - June - 2011 & time between 00.00 midnight to 5.59 AM. Use following code : NSLog(@"Current Date :: %@",[NSDate date]); The O/P is :: Current Date :: 2011-05-31 19:40:21 +0000 Desired O/P is :: Current Date :: 2011-06-01 00:00:0( i.e.the time which is set ) +0000 Also From 6 AM it works fine. What is reason for this? Actually I don't want NSDate in string format but what I want is NSDate date object corresponding to 1st

Comparing certain components of NSDate?

拈花ヽ惹草 提交于 2019-11-30 21:34:08
How would I compare only the year-month-day components of 2 NSDates ? So here's how you'd do it: NSCalendar *calendar = [NSCalendar currentCalendar]; NSInteger desiredComponents = (NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit); NSDate *firstDate = ...; // one date NSDate *secondDate = ...; // the other date NSDateComponents *firstComponents = [calendar components:desiredComponents fromDate:firstDate]; NSDateComponents *secondComponents = [calendar components:desiredComponents fromDate:secondDate]; NSDate *truncatedFirst = [calendar dateFromComponents:firstComponents]; NSDate

Convert String to NSDate in Swift

[亡魂溺海] 提交于 2019-11-30 21:06:37
问题 How to convert this date to NSDate datestring = /Date(147410000000)/ //String from server response Expected Output: 12/01/2014 I tried this. But I got nil. let dateFormatter:NSDateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd/MM/yyyy" let date = dateFormatter.dateFromString(datestring) return date 回答1: " 147410000000 ", i think this the time-interval which you are getting from server. In your case,you need to trim the string and convert it From /Date(147410000000)/ to

Setting NSDate in a “TimePicker” with 24 - 12 hours format xcode

▼魔方 西西 提交于 2019-11-30 20:55:47
问题 I'm working with some NSDate objects, and well, I use my iPhone with 24 hrs format, so when I was testing my app, everything went fine, but, one of my friends tried the app on his iPhone, but he uses 12hrs format, after some research I found out that the problem was the date, and I have no idea why I use this to set a date picker and a time picker, so I read some values from a database (yes, I've checked the values and they are correct, it is not a value-issue), so all this data is formatted

NSDate format in iOS 4.1

岁酱吖の 提交于 2019-11-30 20:53:24
问题 [NSDate date]in iOS 4.0 used to return date in the format: 2010-09-15 09:28:26 +0530 but now in iOS 4.1 it returns the date in the format: 2010-09-15 09:28:26 GMT In my application it is leading to lots of problems. Does anyone know how to fix this? Thanks in advance, YPK 回答1: Thank for your replies. I googled about the problem and somewhere I found that NSDate has a bug in iOS 4.1. So I solved the problem using following method - (NSString *)formattedStringUsingFormat:(NSString *)dateFormat

Objective C: Sort Two Dimensional Array

◇◆丶佛笑我妖孽 提交于 2019-11-30 20:53:00
问题 I have an array of arrays. The contained array's first elements are all NSDate objects. I would like to sort the array containing the arrays in order from most recent to least. For some reason, the below sorting algorithm results in an infinite loop. Can anyone help me out? Thank you. Best...SL //array is the array containing all of the other arrays(that have NSDates as their first elements) //temp is the new array being added to the end of the array, to later be sorted into the correct

NSPredicate and CoreData - decide if a Date attribute is “today” (or between last night 12am to tonight 12am) on iOS

只愿长相守 提交于 2019-11-30 19:12:28
I'm using a NSFetchedResultsController and a UITableViewController to populate a UITableView from a CoreData database. I have a NSDate object saved into this Date attribute labeled "startTime". Then I'm trying to only pull todays's data by using a NSPredicate that looks like this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"startDate == %@", todaysDate]; I'm getting zero results. I understand this because a NSDate object just hold the number of seconds or milliseconds or whatever since Jan 1 1970 right? So comparing 1111111111111 and 1111111111112, while on the same day, are

iPhone SDK NSString To NSDate

混江龙づ霸主 提交于 2019-11-30 19:03:59
I got a string from parsing a XML file which looks like this: Fri, 09 Apr 2010 00:00:45 +0200 and the corresponding pattern should be this "EEE, dd MMM yyyy HH:mm:ss ZZ", but I get (null). This is my code: NSString *dateString = @"Fri, 09 Apr 2010 00:00:45 +0200"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZ"]; NSDate *date = [dateFormatter dateFromString:dateString]; NSLog(@"date:%@",date); // result date:(null) Edit: This works for me now, I had to switch to en-US locale: NSLocale* usLocale = [[NSLocale alloc]

How to get week start date and end date by using any Month and week number swift 3?

巧了我就是萌 提交于 2019-11-30 18:24:31
问题 I have to implement graph so that I need to get week start date and weekend date if I will pass the date object and week number. How can I achieve that I tried it but didn't get exactly? Here below is my code:- Weekday:- //Day of week func getDayOfWeek(today:String)->Int? { let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd" if let todayDate = formatter.date(from: today) { let myCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)! let myComponents =

How do I subclass NSDate?

我与影子孤独终老i 提交于 2019-11-30 17:51:25
问题 I first time tried to subClassed an NSDate to give it 2 methods that I need. Compiles fine, but in runtime I try to access it I get an error. Lets say I just want the current date which is unmodified in the subClass: [myNSDate date]; I get the error -[NSDate initWithTimeIntervalSinceReferenceDate:]: method only defined for abstract class. Define -[myNSDate initWithTimeIntervalSinceReferenceDate:]! what is different? 回答1: NSD’s answer corect, I’ll just try to reiterate in simple terms. NSDate