nsdateformatter

Behavior of NSDateFormatter in iOS 5.1 and iOS 6

…衆ロ難τιáo~ 提交于 2019-12-13 01:34:15
问题 Anyone else noticing some differences between iOS 5.1 and iOS 6.0? In the following, the format of the date string comes back differently in each version:NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; dateFormatter.dateFormat = @"MM/dd/yyyy HH:mm:ss (vvvvv)"; NSDate *lDate = [[NSDate alloc]init]; NSString *sDate = [dateFormatter stringFromDate:lDate]; In iOS 5.1, sDate is "10/01/2012 16:43:09 (GMT-05:00)" but in iOS 6.0, sDate is "10/01/2012 16:44:09 ()" Any

how to get start and end time from datepicker in swift?

二次信任 提交于 2019-12-12 23:46:52
问题 i want to get start and end time from date which i select from datepicker. here is my code func handleDatePicker(sender: UIDatePicker) { let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" let startOfDay = NSCalendar.currentCalendar().startOfDayForDate(sender.date) let components = NSDateComponents() components.hour = 23 components.minute = 59 components.second = 59 let endOfDay = NSCalendar.currentCalendar().dateByAddingComponents(components, toDate:

Date formatter for converting 14-sept-2011 in 14th Sept

家住魔仙堡 提交于 2019-12-12 20:26:17
问题 I have a string 14-Sep-2011 In need to convert this 14th Sept. This date may be any date string. Is there any date formatter which allows me to convert date in my format. As if date is 1-Sept-2011 then I need 1st Sept, 2-Sept-2011 should say 2nd Sept. Can anyone please suggest the solution. Thanks 回答1: - (NSString *)ordinalSuffixFromInt:(int)number { NSArray *cSfx = [NSArray arrayWithObjects:@"th", @"st", @"nd", @"rd", @"th", @"th", @"th", @"th", @"th", @"th", nil]; NSString *suffix = @"th";

How to format data from string variable

谁都会走 提交于 2019-12-12 19:19:06
问题 I have a NSString that keeps date: 1900-01-01T11:00:00 I need to format it, so I have a formatter: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"dd/MM/yyyy hh:mm:ss a"]; How to format this string now? NSString* formatedDateString = [df ???]; 回答1: Create a date formatter, that returns a date object for for the given string, create a second date formatter, that returns a string in the desired format from that date. NSDateformatter *inputFormatter = [[NSDateformatter

iOS Date formatting

心已入冬 提交于 2019-12-12 17:21:02
问题 I need to have the following date formatted while using the application with an US locale: January 1st, July 2nd, November 28th How should I do that? Searched with NSDateFormatter , but I'm not able to set an appropriate format and default formats are too long. 回答1: NSDateFormatter *format = [[NSDateFormatter alloc] init]; [format setDateFormat:@"MMMM dd'st'"]; NSDate *now = [[NSDate alloc] init]; NSString *dateString = [format stringFromDate:now]; NSLog(@"%@",dateString); this will give you

NSDateFormatter problem with weekday EEE

瘦欲@ 提交于 2019-12-12 16:36:36
问题 Why does the following code output: Dday: (null) NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE HH:mm:ss"]; NSDate *date = [dateFormatter dateFromString:@"Sun 15:00:00"]; DLog(@"Ddate: %@", date); If I use the format HH:mm:ss and string 15:00:00 i get a valid date... Cheers mate 回答1: It may be related to the locale of your system/device, have a look at the following from apple http://developer.apple.com/mac/library/qa/qa2010/qa1480.html 回答2

Convert date from timezone to device local timezone and date

三世轮回 提交于 2019-12-12 10:15:39
问题 How can I convert date with timezone1 to date with device local timezone2? NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; [dateFormat setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Jerusalem"]]; NSDate *date = [dateFormat dateFromString:timestamp]; then something like: [dateFormat2 setTimeZone:[NSTimeZone localTimeZone]]; date2 = [dateFormat2 dateFromDate:date withOtherTimeZone:zone]; UPDATE: I think I got it. //get source

How to get Date from String in swift 3?

蹲街弑〆低调 提交于 2019-12-12 09:24:57
问题 I have save the timestamp in data base like: "NSDate()" // which save Date like this: 2017-03-10 22:53:30 +0000 Now i need to get Date from this string, I have tried every format but it's keep returning nil. let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss ZZZ" dateFormatter.locale = Locale(identifier: "en_US") print(dateFormatter.date(from: "2017-03-10 22:53:30 +0000") ?? "No Value") // always return No Value here i have tried so many formats e.g: yyyy-MM

Show time like a digital clock

扶醉桌前 提交于 2019-12-12 09:13:51
问题 I am able to display the current time on my iPad application using the code, NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeStyle: NSDateFormatterShortStyle]; NSString *currentTime = [dateFormatter stringFromDate: [NSDate date]]; timeLabel.text = currentTime; But this gives the time only when the application is loaded. How do i get the time to keep running? Like a digital clock. 回答1: Use this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

Producing an NSDate with NSDateFormatter Yielding nil NSDate Value

倾然丶 夕夏残阳落幕 提交于 2019-12-12 09:11:11
问题 I am trying to produce a date from a string with the following: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MMMM dd, yyyy HH:mm:ss"]; NSLog(@"ENDINGDATE: %@", [closure objectForKey:@"ENDINGDATE"]); NSDate *tempDate = [dateFormatter dateFromString:[closure objectForKey:@"ENDINGDATE"]]; The ENDINGDATE NSLog produces the following: ENDINGDATE: April, 21 2011 20:00:00 Everything seems to be fine, so I am stumped as to why tempDate is being set