nsdate

Parse check if object was created today? Objective-C

跟風遠走 提交于 2019-12-11 19:39:26
问题 I am trying to write a PFQuery for my application that returns only objects that were created today. With all the depreciations that happened to NSDate and the growing importance of NSDateFormatter I am finding rather hard to go about this. I have figured the logic to be like this in pseudo-code: Query q = new Query(); q.whereDateGreaterThan(midnightThisMorning); q.whereDateLessThan(midnightTonight); I can't seem to figure out how to get a NSDate object set to 12:00 AM (which would be

Get Month and year of 1 year advance in iPhone

我怕爱的太早我们不能终老 提交于 2019-12-11 18:35:46
问题 in my app I need to get month name and year for next 1 year and store in array. I mean to say suppose today's September 2012, I need month name and year till August 2013. Can you please tell me how will I get month and year? Thanx in advance 回答1: Use the NSMonthCalendarUnit for the components parameter of the current calendar to get the number of the current month, e.g. 9 for September and then NSYearCalendarUnit for the current year, e.g. 2012. Then use these in a for loop which uses modulus

Sometimes Getting difference of an hour in NSDate

守給你的承諾、 提交于 2019-12-11 18:28:43
问题 I am using IOS 6 and IOS 5. I am getting difference in time of an hour. while I have used the date format as @"MMM d, yyyy HH:mm aaa" . I have also tried @"MMM d, yyyy h:mm aaa" . Actually, I am setting fixed time of notifications for current local. The time is fixed as 10:00AM for different dates. It is displaying date correctly in console but in time is varying as for Australia Time Zone it is displaying "2012-10-02 14:00:00 +0000 or 2012-10-02 13:00:00 +0000" . When I have change the date

Date formatter for the google calender API [duplicate]

倾然丶 夕夏残阳落幕 提交于 2019-12-11 18:23:39
问题 This question already has answers here : Converting NSString to NSDate (and back again) (17 answers) Closed 6 years ago . 1) I am getting the date from the google calender. The format is 2013-05-03T22:30:00.000+02:00 like this. Which date format used for this type of date in the app. 2) I have to show the date like this format Feb 4th 2013 . How to implement these two features in the my app? Please help me. Thank you. 回答1: To get the NSDate from that string: NSDateFormatter *dateFormat = [

Convert NSDate from GMT+0 (London) to User's TimeZone

ぐ巨炮叔叔 提交于 2019-12-11 17:47:44
问题 I have a NSString (date) retrieved from my MySQL database which is in GMT +000 (London) and its format is like this: 12/05/2011 5:21:29 PM. I would like to know how I could convert it to the user's time zone so that if the user was in china for example, it would be that date in the chinese time zone. 回答1: Use setTimeZone: on your input NSDateFormatter . (Internally, NSDate s are time zone agnostic.) E.g.: // The default time zone for a formatter is the time zone of the user's locale

iPhone - comparing dates not working as expected

六月ゝ 毕业季﹏ 提交于 2019-12-11 16:16:02
问题 I have an event that is set to a particular date. I want to check if the date is within 5 minutes range of the current date. For example: if the event is set to 9:10 pm, and now is 9:02 pm. I want to see if the current time is between 9:05 and 9:15 pm. So, I do... NSDate *currentDate ... this variable contains the current date NSDate *plusFive = [eventDate dateByAddingTimeInterval:300]; NSDate *minusFive = [eventDate dateByAddingTimeInterval:-300]; NSComparisonResult result1 = [eventDate

core-data NSDate searching for unique days and sorting

放肆的年华 提交于 2019-12-11 15:45:28
问题 Lots of information on NSDates about the place, but I haven't found a clear solution to this. I have a list of Event entities, each with potentially many EventSessionTime s. Event <--->> EventSessionTime In 1 table view I want to display a unique list of days that have Events , in another table view I want to show the events on a particular day (ordered by time). To achieve this I currently have 2 NSDates - a day and time - and some overly complicated searching/sorting. I want to remove this

How to parse these time zones with NSDateFormatter?

可紊 提交于 2019-12-11 15:04:34
问题 I'm parsing a large number of internet dates. First I try a formatter with en_US_POSIX locale, then with en_GB . The code looks more or less like this: { NSDate *date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_US_POSIX"]; if (date) return date; date = [dateString dateWithDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z (zzz)" localeIdentifier:@"en_GB"]; return date; } - (NSDate*) dateWithDateFormat:(NSString*)dateFormat localeIdentifier:(NSString*

I want to convert NSString to NSDate but UIPickerView shows current date

三世轮回 提交于 2019-12-11 14:44:18
问题 I want to convert NSString to NSDate but UIPickerView shows current datedatePicker=[[UIDatePicker alloc]init]; datePicker.userInteractionEnabled=YES; datePicker.minuteInterval=5; NSLog(@"Date"); //////// NSString *curDate=alarmData.date; //Jan 14, 2011 11:37 NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"MMM dd, yyyy HH:mm"]; //Optionally for time zone converstions [format setTimeZone:[NSTimeZone timeZoneWithName:nil]]; NSDate *da = [format dateFromString

How to find difference, compare and get each field values in NSDate variables?

浪子不回头ぞ 提交于 2019-12-11 14:24:33
问题 How can i do the following operations on NSDate variables? How to compare two NSDate variables? How to find difference between two NSDate variables? How to get each separate value of minute, hours and days from NSDate variable? We can get the current date by NSDate *currentDate=[NSDate date]; But it will give the result of yyyy-mm-dd hh:mm:ss GMT From this, can i get hour field alone? or month value only? 回答1: From NSDate class reference, you have instance methods to do these - How to compare