ios,iphone,swift,xcode6,nsdateformatter
My friend looked at the code and point out the problem. This problem is caused by the differences of the date format between Chinese/Japanese and English. In Chinese/Japanese, the date format is year/month/date. But in English, the date format is month/date/year. In my code, I set the dateStyle into ShortStyle...
You can use the localized string from date function like this... extension NSDate { func localizedStringTime()->String { return NSDateFormatter.localizedStringFromDate(self, dateStyle: NSDateFormatterStyle.NoStyle, timeStyle: NSDateFormatterStyle.ShortStyle) } } ...
Remove the line with the NSDateFormatterStyle: let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "dd.MM.yyyy HH:mm" dateFormatter.locale = NSLocale(localeIdentifier: "en_US_POSIX") let timestamp = dateFormatter.dateFromString("07.07.2015 19:07") This is because setting an NSDateFormatterStyle overrides dateFormatter.dateFormat, making the results nil when using both. The solution is to not use NSDateFormatterStyle if you already have a...
Use the following string format dateFor.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ" ...
objective-c,nsdate,nsdateformatter
TLDR: [NSDate dateWithTimeIntervalSince1970:0] represents the date you're asking for. It is the conversion of that NSDate to a string that involves your time zone. As humans, we have many ways to represent an instant in time. For example, “January 1, 2001 00:00:00 GMT” represents a particular instant in time. Another...
ios,objective-c,nsdate,nsdateformatter
The format string you specified is not correct. The month and day fields are in wrong place (That need to be interchanged). You need to change that to: [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; ...
ios,objective-c,nsdate,nsdateformatter
I did not understand what you meant by "The time is formatted with 'time from 1970'" But here is how to convert a string formatted long containing the number of seconds since 1970 to a NSDate object: NSDate * date = [NSDate dateWithTimeIntervalSince1970:[longValueString longLongValue]]; Sometimes the time coming from the...
ios,objective-c,nsdate,nsdateformatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]]; [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]]; // "Fri, 19 Jun 2015 20:05:23 GMT" [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss zzz"]; ...
Setting dateStyle or timeStyle will override any custom dateFormat you have set. Your date string does not conform in any way to NSDateFormatterShortStyle, which is why you are getting nil when trying to convert strings to dates. Furthermore, according to Unicode Technical Standard #35 revision 31, the timezone specifier of...
swift,date,nsdate,nsdateformatter,nstimeinterval
This method only saves minutes. My suggestion is to save it as time interval var interval = NSDate().timeIntervalSince1970 And then load it up by adding that time to 1970 date like this var date = NSDate(timeIntervalSince1970: interval) ...
let dateShow = formatter.dateFromString(v["feedDate"].description) I would first check if v["feedDate"] isn't an optional, because in this case the v["feedDate"].description would probably contain string like Optional("2015-05-10T18:39:55+02:00") as opposed to 2015-05-10T18:39:55+02:00, which obviously won't get converted to NSDate... Edit: Under your original post you provided this information: this is what it's...
"CEST" is a "short specific non-location format" and the corresponding date field symbol is "z", not "v": [inputFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss z"]; In addition, you might have to set the date formatter locale explicitly to "en_GB" as explained in Nsdateformatter + Timezone issue....
objective-c,cocoa,cocoa-touch,nsdate,nsdateformatter
I would hazard a guess that item[@"enddata"] is already an NSDate object and not an NSString object. Verify with: NSLog(@"enddata is type %@", NSStringFromClass([item[@"enddata"] class])); Also don't use valueForKey:, but instead use objectForKey: or the newish access syntax I've used above....
nsdate,nsuserdefaults,nsdateformatter
Retrieve the NSDate object from NSUserDefaults by calling punchTimes.objectForKey("punchInTime") Then use NSDateFormatter class to create a String formatted the way you want it....
ios,swift,nsstring,nsdate,nsdateformatter
If you're working with fixed-format dates, you should first set the locale of the date formatter to something appropriate for your fixed format. In most cases the best locale to choose is en_US_POSIX, a locale that's specifically designed to yield US English results regardless of both user and system...
ios,swift,core-data,nsdateformatter
You can create only one instance on NSDateFormatter and use it where you need it: lazy var dateFormatter: NSDateFormatter = { let f = NSDateFormatter() f.locale = NSLocale(localeIdentifier: "en_US_POSIX") f.timeZone = NSTimeZone(abbreviation: "GMT+0:00") f.dateFormat = "dd-MM-yyyy" return f }() ...
swift,nsdate,nsdateformatter,nsdatecomponents
Just add the following line formatter.calendar = calendar ...
ios,ios8,nsdate,nsdateformatter
The problem is that you lose the sub-second accuracy in conversion. When creating [NSDate now], the sub-second information is kept in NSDate object. Then you convert it to string that does not keep that information, and after the conversion back it's simply gone. As the documentation for isEqualToDate: states: This...
objective-c,nsdate,nsdateformatter,ios8.1
It all comes down to knowing your format code strings. You are misusing "HH" here so the hour is coming out wrong. Another problem is that you are not capturing the error. By calling dateFromString:, you are missing out on your chance to hear about errors. Use getObjectValue:forString:range:error: to learn...
ios,objective-c,nsdateformatter
Your date format for 24 hours (uppercase H), just change it to use 12 hours (lowercase h): [dateFormatter setDateFormat:@"MMM dd, yyyy hh:mm:ss a"] You can find date format patters here...
ios,ios7,ios8,nsdate,nsdateformatter
You want to be using yyyy instead of YYYY. The small y is the calendar year, whereas the capital Y is the year of the "week of year". Below is an explanation from the specification. F.4 Week of Year Values calculated for the Week of Year field range from 1...
ios,objective-c,nsdate,nsdateformatter
The format string should be [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"]; Note the upper case .SSS. And for the locale, you should specify @"en_US_POSIX" as advised in Technical Note TN1480. This will ensure that you can successfully parse this RFC 3339/ISO 8601 formatted date, regardless of the user's localization settings....
ios,objective-c,nsdate,nsdateformatter
try this... //Getting date from string NSString *dateString = @"09-03-2015"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"dd-MM-yyyy"]; NSDate *date = [[NSDate alloc] init]; date = [dateFormatter dateFromString:dateString]; // converting into our required date format [dateFormatter setDateFormat:@"EEEE, MMMM dd, yyyy"]; NSString *reqDateString = [dateFormatter stringFromDate:date]; NSLog(@"date is %@", reqDateString); LOG:2015-03-09...
ios,swift,nsdate,nsdateformatter
First of all, you have your formatter wrong... let formatter = NSDateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'hh:mm:ss.SSS'Z'" var output = formatter.dateFromString("2000-01-01T00:00:00.000Z") After that, you can get the hour component with if let date = output { var hours = NSCalendar.currentCalendar().component(.HourCalendarUnit, fromDate: date) } ...
ios,swift,nsdate,nsdateformatter,nsdatecomponents
You can achieve this by changing your second line from 1 to -1 like this var comp = NSDateComponents() comp.setValue(-1, forComponent: NSCalendarUnit. CalendarUnitSecond); let date: NSDate = NSDate() var expirationDate = NSCalendar.currentCalendar().dateByAddingComponents(comp, toDate: date, options: NSCalendarOptions(0)) Hope it will help you....
Something along these lines, perhaps: let d = // the date let df = NSDateFormatter() let format = NSDateFormatter.dateFormatFromTemplate( "dMMMM", options:0, locale:NSLocale.currentLocale()) df.dateFormat = format let s = df.stringFromDate(d) Note that both language and region settings on the device are involved in the outcome....
The problem there is that Y is for weekOfYear. You have to use "dd-MM-yyyy"
ios,objective-c,nsdateformatter
You have to set the date format as the string NSString *myDate = @"06/18/2015 8:26:17 AM"; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yyyy h:mm:ss a"]; NSDate *date = [dateFormatter dateFromString:myDate]; //Set New Date Format as you want [dateFormatter setDateFormat:@"dd.MM. HH:mm"]; [dateFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US"]]; NSLog(@"%@",[dateFormatter stringFromDate:date]); ...
ios,objective-c,xcode,nsdate,nsdateformatter
Use following code, NSString *string = @"15:00"; NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init]; [inputDateFormatter setDateFormat:@"HH:mm"]; NSDate *date = [inputDateFormatter dateFromString:string]; NSDateFormatter *outputDateFormatter = [[NSDateFormatter alloc] init]; [outputDateFormatter setDateFormat:@"hh:mm a"]; NSString *outputString = [outputDateFormatter stringFromDate:date]; ...
ios,nsdate,nsdateformatter,nsdatecomponents
It looks like there are two questions here. The first one is about natural language date formatting, and I think you might find this relevant. The second question looks like you're having some confusion about time zones. NSDate is going to parse your date assuming GMT absent any indication of...
ios,objective-c,iphone,nsdate,nsdateformatter
The problem with your code is that your are initialising the NSDateComponents with day 1, and since you are not providing any year, it is taking year as "1". So for your code to work properly, you may set the year of the current date as the NSDateComponents' year. NSCalendar...
swift,cocoa-touch,nsdate,nsdateformatter,date-parsing
Use MM for the month format. Use stringFromDate to convert your NSDate to a String. Then convert your string to an Int with .toInt() let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "MM" let monthString = dateFormatter.stringFromDate(NSDate()) // "05" let monthInt = monthString.toInt() // 5 ...
ios,objective-c,nsdate,nsdateformatter
Please use below code NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZ"]; NSString *dueDateString = [NSString stringWithFormat:@"2014-07-11T15:21:42.207+02:00"]; NSDate *dateFromApi = [dateFormatter dateFromString:dueDateString]; [dateFormatter setDateFormat:@"yyyy/MM/dd"]; NSString *finalDateString = [dateFormatter stringFromDate:dateFromApi]; NSLog(@"dueDateString %@", dueDateString); NSLog(@"dateFromApi %@", dateFromApi); NSLog(@"finalDateString%@",...
cocoa,locale,nsdateformatter,nscalendar
I finally got it. The mistake was in the locale identifier which should be en_AE instead of en_AR import UIKit let arabicLocale = NSLocale(localeIdentifier: "en_AE") let islamicTabularCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierIslamicTabular) islamicTabularCalendar?.locale = arabicLocale let islamicTabularFormatter = NSDateFormatter() islamicTabularFormatter.calendar = islamicTabularCalendar islamicTabularFormatter.dateStyle = NSDateFormatterStyle.FullStyle let gregorianCalendar = NSCalendar(calendarIdentifier:...
objective-c,ios7,nsdateformatter
// Date formatter for your date string: 2014-12-08T14:11:32.636Z NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS'Z'"]; // Date from your string NSDate *date = [dateFormatter dateFromString:@"2014-12-08T14:11:32.636Z"]; // T => Week Day // S => Fractional Second // Z => zone- Time Zone // Updating to your format for preffered style...
ios,iphone,nsdate,nsdateformatter,nslocale
I'm not sure why you expect that the dateFormat changes if the date changes significantly. The significant time change event is triggered when the time (i.e. [NSDate date]) changes. For example if a new day starts, if the user changes timezone or if daylight-saving starts or ends. But those events...
objective-c,nsdate,nsdateformatter
the time is read using your local timezone and the NSDate shown uses UTC time (as it always does when not using a specific date formatter you explicity tell it to use the local timezone [dateFormat setTimeZone:[NSTimeZone defaultTimeZone]]; //! NSDate itself though is a timestamp without any notion of timezones...
ios,objective-c,iphone,string-formatting,nsdateformatter
You need to use HH instead of hh in the date formatting specifier: @"yyyy-MM-dd_HH_mm_ss" ^^ ...
The date template function has a neat trick. There is a template specifier j which will turn into an hour format depending if the locale uses 12 or 24 hour format. It'll turn into something like h a for 12 hour (en_US in this case) or HH for 24 hour...
objective-c,xcode,nsdate,nsdateformatter
NSDateFormatter uses your current timezone (GMT+8) unless you explicitly set. You should set your formatter's timezone as UTC (in other words GMT) to format your date correctly. NSLog(@"Current timezone: %@", [NSTimeZone defaultTimeZone]); NSString *customDate = @"23-06-1993"; NSLog(@"Custom Date: %@", customDate); NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd-MM-yyyy"]; [formatter setTimeZone:[NSTimeZone...
Wrong format, use HH instead of hh. The h directive is for hour in the am/pm format, will not work with 17. See this comprehensive date formatting guide...
The issue is the locale of the formatter. If you want to use gregorian calendar regardless of the device settings, you generally should set locale to en_US_POSIX. formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; See Apple Technical Q&A #1480. This is geared towards RFC 3339/ISO 8601 dates, but it really applies anywhere you're...
ios,objective-c,nsdate,nsdateformatter
Call this method to rationalize an array to "Weekdays" or "Weekend" if it contains the correct days. Else it will leave the array intact. It's easy to change to make it return a string instead, but I'll leave that to you. - (NSArray *)rationalizeDaysOfWeek:(NSArray *)daysOfWeek { if ([self array:daysOfWeek matchesArray:@[...
Your date formatter is not right,try this one [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSSZ"]; And this will output 2015-05-19 10:31:04.530 OCTest[2428:76257] string 2015-05-19T01:48:33.603890Z 2015-05-19 10:31:04.534 OCTest[2428:76257] dateOfCall 2015-05-19 01:48:33 +0000 2015-05-19 10:31:35.113 OCTest[2428:76257] dateString 9:48 AM I am not sure if this is what you want,if you have more questions,feel free to comment...
ios,objective-c,ios8,nsdateformatter,ios7.1
setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZZ" (It's all in the spec if you bother to look.)...
ios,datetime,nsdate,nsdateformatter,date-format
Check your device settings for 24 hour time. If it is on, turn it off. Your code is perfectly fine. I am getting output as shown below : Today's Time: 04:31:58 PM If you don't want to show seconds use this code : [formatter setDateFormat:@"hh:mm a"]; ...
ios,objective-c,cocoa,nsdate,nsdateformatter
You're missing the fractional seconds at the end of the date, you'll need to add them to your format string: yyyy-MM-dd'T'HH:mm:ss.SSS'Z' ...
string,swift,parse.com,nsdateformatter
This is a highly inefficient way of formatting the dates into a String since it instantiates a new NSDateFormatter each time. Consider creating a constant NSDateFormatter for the class as an optimisation. override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! UITableViewCell let formatter...
date,nsdateformatter,date-formatting
Try this: [dateFormatter setDateFormat:@"EEE-MMM-dd-hh:mm:ss-z-yyyy"]; The pattern is case sensitive. For more information see here...
ios,objective-c,nsdate,nsdateformatter,nstimeinterval
That should do the trick: NSDate *now = [NSDate date]; NSTimeInterval totalTime1 = [now timeIntervalSinceDate: timeEntry1]; NSTimeInterval totalTime2 = [now timeIntervalSinceDate: timeEntry2]; NSLog(@"totalTime1: %f", totalTime1); // => -60.00; NSLog(@"totalTime2: %f", totalTime2); // => 6023.00; //must always be this way int timeOffset = (int) (totalTime1 - totalTime2); NSLog(@"timeOffset: %d", timeOffset); //...
I've just tested your provided code on my iOS 7.1 device, and it gave me "3:22", so problem is not device or OS version. Problem is the locale, do like this and it will work - (NSString *)getLastTimeMessageWithPeriod:(NSDate *)lastMessageDate { NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"h:mm a"]; [dateFormatter setLocale:[[NSLocale...
.dateFromStringcreates an NSDate() from a String. The format of the string has to be set with .dateFormat You set the format to "d MMMM" but your myDate variable does not conform to that format. I believe you want to make a String in your "d MMMM" format out of a...
ios,objective-c,iphone,nsdateformatter,date-formatting
After lot of r&d on this topic finally i find the solution for this issue. This uses a special date template string called "j". According to the ICU Spec, "j"... Requests the preferred hour format for the locale (h, H, K, or k), as determined by whether h, H, K,...
According to the documentation, the "Medium" style (that you are specifying) for English is shown as "Nov 23, 1937" so it shouldn't be very surprising that it was shown as "nov" instead of "11" in Italian. NSDateFormatterMediumStyle Specifies a medium style, typically with abbreviated text, such as “Nov 23, 1937”"...
NSDateFormatter follows the Unicode standard for date and time patterns. Use 'H' for the hour on a 24-hour clock: So in your code, the correct way should be: NSString *lastModifiedString = [metaData objectForKey:@"Last-Modified"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss Z"]; NSDate *onlineModDate = [dateFormatter...
ios,objective-c,xcode,nsdateformatter
yyyy specifies the calendar year, whereas YYYY specifies the year (of “Week of Year”) you must change your dateformatter style from [dateFormatter setDateFormat: @"YYYY-MM-dd HH:mm:ss zzz"]; to [dateFormatter setDateFormat: @"yyyy-MM-dd HH:mm:ss zzz"]; for your reference, check this apple documentation...
The error is clearly showing that value is already an NSDate, not an NSString. All of your code can be replaced with one line: NSDate *value = [newProperties objectForKey:key]; You can verify that value is a date by logging its class: NSLog(@"value class = %@", [value class]); As a side...
ios,objective-c,nsdate,nsdateformatter,nstimezone
If you use NSLog to display dates it'll be displayed in UTC. So either you have to convert in your head, or don't use it. I wrote a long answer explaining this to a different question. Because you have set the timezone of your parsing dateFormatter to Paris the string...
ios,date,swift,nsdate,nsdateformatter
It looks like your date formatter is a bit off. "MM'/'DD'/'YYYY" reads "Padded month / day of the year (not month) / year of the current week (so Jan 1-6 could overlap and add side-effects)" I'm guessing that what you're aiming for is "MM'/'dd'/'yyyy", which reads "Padded month / padded...
You need to use an NSCalendar to compute a difference in terms of months and days. Example: let calendar = NSCalendar.autoupdatingCurrentCalendar() calendar.timeZone = NSTimeZone.systemTimeZone() let dateFormatter = NSDateFormatter() dateFormatter.timeZone = calendar.timeZone dateFormatter.dateFormat = "yyyy-MM-dd" if let startDate = dateFormatter.dateFromString("2014-9-15") { let components = calendar.components( NSCalendarUnit.CalendarUnitMonth | NSCalendarUnit.CalendarUnitDay, fromDate: startDate, toDate:...
swift,nsdate,nsdateformatter,nsdatecomponents,nsdatecomponentsformatter
From the headerdoc: /* Bitmask of units to include. Set to 0 to get the default behavior. Note that, especially if the maximum number of units is low, unit collapsing is on, or zero dropping is on, not all allowed units may actually be used for a given NSDateComponents. Default...
ios,objective-c,nsdateformatter
You need to take the fractional seconds into account (and not quote anything expect special characters.) This format string should work: "yyyy'-'MM'-'dd'T'HH':'mm':'S.SSSZZZZZ" ...
ios,objective-c,iphone,nsdate,nsdateformatter
NSString *[email protected]"1992-11-15"; NSDateFormatter *format = [[NSDateFormatter alloc] init]; //Set your input format [format setDateFormat:@"yyyy-MM-dd"]; //Parse date from input format NSDate *dateOfBirth = [format dateFromString:trimmedDOB]; //Set your output format [format setDateFormat:@"MM-dd-yyyy"]; //Output date in output format NSLog(@"DATE IS %@",[format stringFromDate:dateOfBirth]); ...
ios,objective-c,nsdate,nsdateformatter
Please check below code - NSString *[email protected]"01:32 PM"; NSDateFormatter *formatHora = [[NSDateFormatter alloc] init]; [formatHora setDateFormat:@"hh:mm a"]; NSDate *dateHora = [formatHora dateFromString:hora]; [formatHora setDateFormat:@"HH:mm"]; NSString* horaFormatoCorrecto = [formatHora stringFromDate:dateHora]; ...
See: ICU Formatting Dates and Times Also: Date Field SymbolTable., look specifically at "Z". Z Time Zone: ISO8601 basic hms? / RFC 822 -0800 Example: NSString *dateString = @"Fri, 06 Feb 2015 11:25:00 -0600"; NSLog(@"dateString: %@", dateString); Input dateString: dateString: Fri, 06 Feb 2015 11:25:00 -0600 NSDateFormatter *formatter = [NSDateFormatter...
The conversion is done in your local time zone, while simply printing a date it will be printed in GMT (hence "… +0000") NSLog(@"%@", [df stringFromDate:date]); This will print the date in local time zone...
ios,objective-c,nsdateformatter
You are missing a 'y' in your format. It should be: NSDateFormatter *formatter = [[NSDateFormatter alloc]init]; formatter.dateFormat = @"dd.MM.yyyy HH:mm:ss"; return [formatter dateFromString:dateString] ...
ios,swift,datetime,nsdateformatter
Besides the problem that the string you were testing had milliseconds while the date from your array has only seconds, now the problem is that Y is for week of year. You need to use lowercase "y" with the date format and also lowercase "d". The date format should look...
Playground test: let lc = "zh-cn"; var locale = NSLocale(localeIdentifier: lc); var format = NSDateFormatter.dateFormatFromTemplate("yyyyMMM", options: 0, locale: locale); var formatter = NSDateFormatter(); formatter.dateFormat = format; formatter.locale = locale; formatter.stringFromDate(NSDate()); Production code: var format = NSDateFormatter.dateFormatFromTemplate("yyyyMMM", options: 0, locale: nil); var formatter = NSDateFormatter(); formatter.dateFormat = format; let dateString =...
ios,objective-c,nsdate,nsdateformatter
Your @autoreleasepool is in the wrong place. You ned to be draining the pool at the end of each loop: for ( NSDictionary *dic in array) { @autoreleasepool { NSDate *date = [millisecondDateFormatter dateFromString:[dic objectForKey:@"key"]]; obj.nestedObj.startTime = date; date = nil; } } That said, I assume your real code...
The problem is that dateFromString: depends on the timezone of your NSDateFormatter. So you need to tell your formatter, which timezone to use: NSString *serverDateString = array[0]; NSString *nextEventDateString = array[1]; NSDateFormatter *dateFormatter = [NSDateFormatter new]; [dateFormatter setDateFormat:@"hh:mm dd.MM.yyyy"]; // Set the time zone here [dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"CET"]]; // If...
objective-c,cocoa,cocoa-touch,nsdateformatter
The date formatter uses the style if format is nil. So add the following line: df.dateFormat = nil; when you want to go back to use the style....
You just need to set the locale identifier to "pt_BR" // this returns the date format string "dd 'de' MMMM 'de' yyyy" but you still need to set your dateFormatter locale later on let br_DateFormat = NSDateFormatter.dateFormatFromTemplate("ddMMMMyyyy", options: 0, locale: NSLocale(localeIdentifier: "pt_BR")) let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = br_DateFormat dateFormatter.locale...
objective-c,cocoa,date,nsdateformatter
Try this: NSDateFormatter* formatter = [NSDateFormatter new]; formatter.timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; formatter.shortMonthSymbols = @[@"0", @"1", @"2", @"3", @"4", @"5", @"6", @"7", @"8", @"9", @"10", @"11"]; formatter.dateFormat = @"yyyy MMM dd"; // Note 3 Ms for "short month" format NSDate* theDate = [formatter dateFromString:@"2002 0 20"]; Result: 2002-01-20 00:00:00 +0000 ...
The problem is you are quoting the timezone format specifier. You want: [formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSSZ"]; Note the lack of quote before the Z....
objective-c,nsdate,nsdateformatter
I've finally ended up using this code: NSString *dateStringWithTZ = @"2015-04-18T08:35:00.000+03:00"; // Create date object using the timezone from the input string. NSDateFormatter *dateFormatterWithTZ = [[NSDateFormatter alloc] init]; dateFormatterWithTZ.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSZ"; NSDate *dateWithTZ = [dateFormatterWithTZ dateFromString:dateStringWithTZ]; // Cut off the timezone and create date object using GMT timezone. NSString *dateStringWithoutTZ...
ios,nsdate,nsdateformatter,nstimezone
Again: when you say "in local time", you mean local to the returned string, not to the user? So I get sent a date from Germany, I have enough information both to turn it into an NSDate and so that I could create an NSDateFormatter that recreated exactly the original...
objective-c,nsstring,nsdate,nsdateformatter
NSString * dateStr = @"13th May-2015"; NSArray *stringComponentArray = [dateStr componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; NSMutableArray *workingArray = [NSMutableArray arrayWithArray:stringComponentArray]; NSMutableString *dateString = [[NSMutableString alloc]initWithString:[workingArray firstObject]]; [dateString replaceOccurrencesOfString:@"st" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0,[dateString length])]; [dateString replaceOccurrencesOfString:@"nd"...
NSDateFormatter Class Reference : http://goo.gl/7fp9gl Date Formatting Guide (Apple) : http://goo.gl/8zRTQl A common mistake is to use YYYY. yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. Your code should work, as you expect, like this : let dateStr...
ios,objective-c,nsstring,nsdateformatter
NSString *str = @"2015-05-08T09:44:25.343"; NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; [dateFormat setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss.SSS'Z'"];// this string must match given string @"2015-05-08T09:44:25.343" NSDate *date = [dateFormat dateFromString:str]; NSLog(@"%@",date); [dateFormat setDateFormat:@"MM/dd/yyyy"];// this match the one you want to be NSString *convertedString = [dateFormat stringFromDate:date]; NSLog(@"%@", convertedString); ...
To get the hour and minutes component, you do this: NSDateComponents *components = [[NSCalendar currentCalendar] components:(NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:date]; NSInteger hour = [components hour]; NSInteger minute = [components minute]; You can then create helper methods to keep the code organized: - (NSInteger)hourFromDate:(NSDate *)date { return [[NSCalendar currentCalendar] component:(NSCalendarUnitHour) fromDate:date]; }...
Hate to break it :) Think it might be: "yyyy-MM-dd HH:mm:ss" not "yyyy-MM-dd HH:mm" ?...
check the following code: var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" let d = NSDate() let s = dateFormatter.stringFromDate(d) println(s) ...
Change with this one: [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss a"]; ...
ios,objective-c,nsdate,nsdateformatter
Try this you will get output: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"hh:mm a"]; NSDate* selectedTime = [dateFormatter dateFromString:@"11:22 AM"]; NSDate* myTime = [selectedTime dateByAddingTimeInterval:-60*10];//10 minute deduction NSString* updateTime = [dateFormatter stringFromDate:myTime]; NSLog(@"New Time %@",updateTime); Output : New Time 11:12 AM Here you are subtracting 10 Minutes from selected...
ios,objective-c,nsdate,nsdateformatter,nsdatecomponents
It's due the difference between your timezone and UTC. The value 2029-12-31T00:00:00+00:00 is on December 31 in the UTC timezone. But when you setup the date components you are getting back the date in your timezone where it's December 30 local time.
swift,nsdateformatter,timezoneoffset
If you want to convert a show time which is stored as a string in GMT, and you want to show it in the user's local time zone, you should not be manually adjusting the NSDate objects. You should be simply using the appropriate time zones with the formatter. For...
swift,nsdate,nsdateformatter,uidatepicker
I think I've fixed it. I think the thing that was causing problem was that I was setting locale to currentLocale but then 2 lines down specifying a dateFormat which would work if it corresponds to the current locale but not otherwise. Anyway, fix appears to be just specify locale...
objective-c,nsdate,nsdateformatter
If you want to get current day like format this: dd/MM/yyyy. You can use this code: NSDate *datecenter = [NSDate date]; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"d, MMMM, YYYY"]; NSString *dateString = [dateFormat stringFromDate:datecenter]; lbldaymonthyear.text = dateString; ...
ios,objective-c,nsdate,nsdateformatter
modify the date formatter YYYY to yyyy you can get exact values [dateFormatter setDateFormat:@"dd/MM/yyyy"]; yyyy specifies the calendar year whereas YYYY specifies the year (of “Week of Year”), used in the ISO year-week calendar. In most cases, yyyy and YYYY yield the same number, however they may be different. Typically...
I got the solution for this itself only needed to replace [formatter setDateFormat:@"yyyy-mm-dd hh:mm:ss"]; with [formatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; and it worked....
Surely you could just use substringFromIndex on the string, something that should work for the next eight thousand years or so (a). In other words, something like: self.julian.text = [[julianFormatter stringFromDate:julianLabel] substringFromIndex:3]; (a) It'll work as per your specification until we reach the year 10,000 but keep in mind you'll...
ios,objective-c,nstimer,nsdateformatter
The problem is that you have two different updateTimers -- self.updateTimer the class variable and updateTimer the local variable. You're invalidating the class variable, but initializing and running multiple local NSTimers with different locales during each call to startTimer. That's why you see this "flickering" -- it's because multiple NSTimers...
ios,objective-c,nsstring,nsdate,nsdateformatter
-(NSString *)geTimeFromString:(NSString *)string { NSString * dateString = [NSString stringWithFormat: @"%@",string]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"hh:mm:ss"]; NSDate* myDate = [dateFormatter dateFromString:dateString]; [dateFormatter setDateFormat:@"hh:mm a"]; [dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; NSString *stringFromTime = [dateFormatter stringFromDate:myDate]; return stringFromTime; } Try this...
ios,date,swift,nsdate,nsdateformatter
Should be like this if you want to skip all the 0: yyyy-MM-ddTHH:mm:ss The ISO standard format is yyyy-MM-dd'T'HH:mm:ss.SSS'Z'...
Modify your code as below. NSString *dateStr = @"2015-02-04T01:02:27.363Z"; NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.zzzZ"]; NSDate *date = [dateFormat dateFromString:dateStr]; ...