nsdate

NSDateFormatter not working properly?

故事扮演 提交于 2019-12-02 11:56:05
My code , -(NSString *)trimDateStringInRequiredFormat:(NSString *)dateInString{ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSDate *date = [dateFormatter dateFromString:dateInString]; [dateFormatter setDateFormat:@"hh:mm aaa"]; NSString *dateDisplay = [dateFormatter stringFromDate:date]; return dateDisplay; } The above worked properly when my date is 2012-06-06 12:00:00 and I got appropriate output like 12:00 AM. But when I send my date like 2012-06-06 15:00:00 it doesn't return me appropriate output, instead, it

Issues converting DATETIME using SQLITE3 and Objective C

让人想犯罪 __ 提交于 2019-12-02 10:53:17
I have a sqlite3 Database with a DATETIME column containing values formatted like this: 2013-01-09 04:00:00 I'm trying to figure out how to determine if times are AM or PM? Here's how I read and convert the DATETIME objects from my Sqlite3 DB using Objective-C: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; char *DateTimeColumn = (char *)sqlite3_column_text(statement, 13); NSDate *myDate =[dateFormat dateFromString:[NSString stringWithUTF8String:DateTimeColumn]]; This works really well except it doesn't figure out whether this

Date format for 2016-10-20T13:01:47.317

余生长醉 提交于 2019-12-02 10:31:12
This is what I am trying for getting date from the string 2016-10-20T13:01:47.317 but getting nil NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; dateString = [dateString substringToIndex:dateString.length - 3]; [dateFormatter1 setDateFormat:@"YYYY-MM-ddTHH:mm:ss"]; NSDate *date = [dateFormatter1 dateFromString:dateString]; Also tried with yyyy but still getting nil. I was not able to understand .317 so I eliminated that from the string. What shall be the date format for this ? it .317 means milliseconds use SSS NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]

Set current time to yyyy-MM-dd 00:00:00 using Swift

核能气质少年 提交于 2019-12-02 10:20:36
问题 I want to ask about NSDate , how to set/format current time like "2015-08-12 09:30:41 +0000" to "2015-08-12 00:00:00 +0000 I'm already using : var dateFormatter = NSDateFormatter() dateFormatter.dateStyle = .MediumStyle dateFormatter.timeStyle = .NoStyle //result date will be : Aug 12, 2015 but the value date is not stored in the Database exactly as "2015-08-12 00:00:00 +0000" but storing as "2015-08-11 17:00:00 +0000 UTC" 回答1: let dateString = "2015-08-12 09:30:41 +0000" let dateFormatter =

Weird behavior when creating an NSDate of January the 1st and the 2nd

会有一股神秘感。 提交于 2019-12-02 09:58:47
问题 I'm creating a date like this : NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY"]; NSInteger year = [[dateFormatter stringFromDate:[NSDate date]] intValue]; NSLog(@"NSInteger YEAR : %d\n", year); //minutes, hours, day and month are initialized elsewhere... NSDateComponents *comps = [[NSDateComponents alloc] init]; [comps setYear:year]; [comps

How to sort the Array that contains date in strings in descending order? [duplicate]

梦想与她 提交于 2019-12-02 09:30:43
问题 This question already has answers here : NSDateFormatter return incorrect date from string (3 answers) Closed 6 years ago . I want to sort the array that contains date string in descending order, I have tried SO answers, but I am getting wrong output. Please see my code as below: NSArray *dateArray=[NSArray arrayWithObjects:@"01/12/2012",@"01/26/2011",@"02/09/2005",@"02/24/2006",@"03/19/2007",@"07/14/2011",@"08/17/2007",@"10/04/2007",@"10/31/2006",@"12/05/2012",@"12/06/2006",@"12/23/2008",nil

Converting NSDate to NSString causes unrecognized selector exception

烂漫一生 提交于 2019-12-02 09:21:12
问题 I am storing an NSDate in a plist as a string, and at launch I am trying to convert the string from the plist back to an NSDate to compare it later. This is how I am storing the value in my plist: [InfoDic setValue:[NSDate date] forKey:@"LastDate"]; In the log (When I convert the [NSDate date] to a proper string) it says this: 2013-04-13 22:47:57 +0000 This is how I am trying to convert the plist value back to an NSDate : NSString *Checkdate= [InfoDic objectForKey:@"LastDate"];

NSDate from stange looking string

随声附和 提交于 2019-12-02 09:03:07
I have an NSDictionary with the value for date as: "Date":"/Date(1314313200000+0100)/", How can I turn this into an NSDate as it contains strings lie "Date": and / ? 1314313200000 is milliseconds since the epoch-date (1970-01-01), and 0100 is the timezone. You need to parse this info out from the string and build a date from it. The NSScanner class is a good fit for parsing information out of strangely formatted text. // Init a scanner with your date string NSScanner* scanner = [NSScanner scannerWithString:@"Date:/Date(1314313200000+0100)/"]; // Skip everything up to a valid numeric character

iPhone SDK, how to get NSDate object of coming friday's 20:00?

吃可爱长大的小学妹 提交于 2019-12-02 08:46:43
问题 Does anyone know how to get the NSDate of the coming friday's 20:00 ? 回答1: Yes, this article teaches you how to get the current week's Sunday. I quickly adapted it to get friday at 20:00 (Assuming a Gregorian calendar) NSDate *today = [[NSDate alloc] init]; NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; // Get the weekday component of the current date NSDateComponents *weekdayComponents = [gregorian components:NSWeekdayCalendarUnit fromDate:today]

NSDate delay date change

僤鯓⒐⒋嵵緔 提交于 2019-12-02 08:44:37
问题 This is probably a simple solution but does anyone know how to delay the NSDate change past midnight? Any insight would be really helpful, thanks! Edit: I am currently getting the date this way and displaying a locations data based on that day. But, much like the NSDate is logically supposed to work, it switches to the next day at midnight. I want the date to change at 3am instead of at 12am. NSDateFormatter *f = [[NSDateFormatter alloc] init]; [f setDateFormat:@"EEEE"]; today = [f