nsdate

IOS how to set date format [duplicate]

*爱你&永不变心* 提交于 2019-11-30 13:28:02
This question already has an answer here: Converting an ISO 8601 timestamp into an NSDate: How does one deal with the UTC time offset? 5 answers I have a string like this NSString *datestr = @"2013-08-06T03:51:54+00:00"; I try to set dateformat as below: NSDateFormatter *dformat = [[NSDateFormatter alloc]init]; [dformat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"]; NSDate *date = [dformat dateFromString:datestr]; But the date will be nil, so, can anyone tell me how to set the dateformat, thx! Try this: NSDateFormatter *dformat = [[NSDateFormatter alloc]init]; [dformat setDateFormat:@"yyyy-MM-dd'T

Convert date in MM/dd/yyyy format in xcode?

笑着哭i 提交于 2019-11-30 13:15:26
问题 I have a UIDatePicker and I m getting the selected date from it in yyyy-MM-dd format.Now I want to convert it to MM/dd/yyyy format ..How can i do it ? NSDateFormatter *df=[[[NSDateFormatter alloc]init] autorelease]; df.dateFormat = @"yyyy-MM-dd"; NSArray *temp=[[NSString stringWithFormat:@"%@",[df stringFromDate:DatePicker.date]] componentsSeparatedByString:@""]; [dateString2 release]; dateString2=nil; dateString2= [[NSString alloc]initWithString:[temp objectAtIndex:0]]; NSLog(@"%@"

Adding days to NSDate

寵の児 提交于 2019-11-30 12:43:13
I want add days to a date, I got many codes for this but none of them are working for me below shown is my code,please somebody help me to fix this issue int daysToAdd=[[appDlegateObj.selectedSkuData objectForKey:@"Release Time"] intValue]; NSTimeInterval secondsForFollowOn=daysToAdd*24*60*60; NSString *dateStr=[contentDic objectForKey:@"Date"]; NSDateFormatter *dateFormatter=[[NSDateFormatter alloc]init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSDate *dateFromString=[[NSDate alloc]init]; dateFromString=[dateFormatter dateFromString:dateStr]; [dateFormatter release]; NSDate *date=

Swift: using UIDatePicker as UITextField inputView not updating

别等时光非礼了梦想. 提交于 2019-11-30 12:36:55
问题 I have a textfield and when it is selected a datepicker pops up instead of a keyboard, but it only updates with todays date the first time. The user changes the date, but the textfield does not continue to update. What is the problem? This is how I call the Datepicker and control the date being inputted into my textfield: @IBAction func dp(sender: UITextField) { var DatePickerView : UIDatePicker = UIDatePicker() DatePickerView.datePickerMode = UIDatePickerMode.Date textfieldjobdate.inputView

sorting an NSArray of NSDates

◇◆丶佛笑我妖孽 提交于 2019-11-30 12:14:50
I have an NSArray of NSDate objects and I want to sort them so that today is at 0, yesterday at 1 etc. Is it ascending or descending, and do i use a function, selector or what? There are different sort methods for NSArray because there may be different ways you want to sort things. NSSortDescriptors are a general way that give you a lot of options as far as what keys to use in sorting, what selectors you want to use on those keys, and overall order to use, etc. Or you can use functions or comparator blocks instead if your case requires that or if that's more convenient for your particular case

Create NSDate for today at a particular hour and minute

本秂侑毒 提交于 2019-11-30 10:25:55
How can I create an NSDate with today's date and an hour, minutes, and seconds of 5, 0, and 0 respectively? I.e. the date will be 07/02/2010 05:00:00 //Gives us the current date NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateComponents *components = [gregorian components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit fromDate:[NSDate date]]; [components setHour:5]; NSDate * date = [gregorian dateFromComponents:components]; [gregorian release]; Something along those lines should do the trick. 来源: https://stackoverflow.com

swift - Convert a String to a Date and then to a String in a different format

余生颓废 提交于 2019-11-30 10:20:29
Suppose I have a simple String, extracted from an array of strings (representing dates) - var myDateString = "2015-11-25 04:31:32.0" Now, I want to convert it to a string that looks like Nov 25, 2015 . For that, I assume I need to - get a NSDate date object from string using NSDateFormatter get a string from that NSDate object by using some functionality (which I've been unable to find) I've been trying this in Playground, but have been unable to solve such a simple problem. Here is what I have tried - Line 1| var dateFormatter = NSDateFormatter() Line 2| dateFormatter.locale = NSLocale

NSString to NSDate conversion problem

人盡茶涼 提交于 2019-11-30 10:15:33
I am having a NSString object which I am converting to NSDate with help of NSDateFormatter. Now code works fine here with all the OS but it is creating different Output at client's add (USA region). Here is the code that I am using. NSDateFormatter *formate = [[[NSDateFormatter alloc] init] autorelease]; [formate setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; NSString *strConcat = @"2010-09-24 17:30:00"; NSDate *date = [formate dateFromString:strConcat]; NSLog(@"Output :%@",date); Output at my end -------2010-09-24 17:30:00 - 0700 Output at Client end ----2010-09-25 00:30:00 GMT Can anyone please

How to determine if locale's date format is Month/Day or Day/Month?

旧城冷巷雨未停 提交于 2019-11-30 08:59:43
In my iPhone app, I'd like to be able to determine if the user's locale's date format is Month/Day (i.e. 1/5 for January fifth) or Day/Month (i.e. 5/1 for January fifth). I have a custom NSDateFormatter which does not use one of the basic formats such as NSDateFormatterShortStyle (11/23/37). In an ideal world, I want to use NSDateFormatterShortStyle, but just not display the year (only month & day#). What's the best way to accomplish this? You want to use NSDateFormatter's +dateFormatFromTemplate:options:locale: Here is some Apple sample code: NSLocale *usLocale = [[NSLocale alloc]

iOS Daily Local Push Notifications

眉间皱痕 提交于 2019-11-30 08:50:21
问题 I want to execute a UILocalNotification at 9:00 AM every day, forever, as long as the app is open. The closest thing I've found is this: UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [[NSDate date] dateByAddingTimeInterval:60*60*24]; notification.alertBody = @"It's been 24 hours."; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; However, this code only executes a UILocalNotification once in 24 hours, not at a