nsdateformatter

Convert NSDate to NSString with NSDateFormatter with TimeZone without GMT Time Modifier

爷,独闯天下 提交于 2020-01-01 01:18:14
问题 I'm initializing my NSDateFormatter thusly: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]]; [dateFormatter setDateFormat:@"EEE, d MMM yyyy HH:mm:ss z"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; NSDate *date = [NSDate date]; NSString *dateString = [dateFormatter stringFromDate:date]; dateString is now: Thu, 29 Jul 2010 14:58:42 GMT+00

DateFormatter returns wrong time [duplicate]

僤鯓⒐⒋嵵緔 提交于 2019-12-31 05:53:07
问题 This question already has answers here : Getting date from [NSDate date] off by a few hours (3 answers) Closed 2 years ago . I did an extension for Date that returns a formatted string: extension Date { var myFormattedDate : String { let formatter = DateFormatter() formatter.timeZone = TimeZone.current formatter.dateFormat = "EEEE, MMMM d, y (HH:mm a)" return formatter.string(for: self)! } } On runtime, I set a breakpoint inside the myFormattedDate property. po self printed: 2017-09-05 08:50

Convert date format in returns wrong date xcode [duplicate]

限于喜欢 提交于 2019-12-31 03:57:09
问题 This question already has an answer here : NSDateFormatter show wrong year (1 answer) Closed 2 years ago . I want to convert date from 23 May, 2017 to 23-05-2017 . I have tried with the following code but it returns 25-12-2016 . NSDateFormatter *oldFormatter = [NSDateFormatter new]; [oldFormatter setDateFormat:@"dd MMM, YYYY"]; NSDate *oldDate = [oldFormatter dateFromString:dateStr]; NSDateFormatter *newFormatter = [NSDateFormatter new]; [newFormatter setDateFormat:@"dd-MM-YYYY"]; I am using

Formatting date with Swift

泄露秘密 提交于 2019-12-31 03:29:07
问题 I am trying to Convert a String into Date using Date Formatter . var dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd’T’HH:mm:ss’Z’" var AvailabletoDateTime = dateFormatter.dateFromString("2015-07-16’T’08:00:00’Z’") But the AvailabletoDateTime is Returning nil . Can Someone please Help me ,and let me know if i miss Anything Here . 回答1: Try like this: let dateFormatter = NSDateFormatter() dateFormatter.calendar = NSCalendar(calendarIdentifier:

How to convert server response date to local timezone?

冷暖自知 提交于 2019-12-30 07:32:32
问题 In api call response I'm getting dates in different timezone. I want to convert it to user's local timezone plus user can select any timezone from the list of ios timezone. This is all local. We would never be sending selected user timezone to server. And while making any api call lets say i am creating an event with selected start date in a picker. I should send it global timezone not with the user selected timezone because it is local to the app. Currently I am changing defaultTimeZone on

How to configure DateFormatter to capture microseconds

戏子无情 提交于 2019-12-30 06:28:52
问题 iOS Date() returns date with at least microsecond precision. I checked this statement by calling Date().timeIntervalSince1970 which results in 1490891661.074981 Then I need to convert date into string with microsecond precision. I am using DateFormatter in following way: let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSSZZZZZ" print(formatter.string(from: date)) which results in "2017-03-30T16:34:21.075000Z" Now if we compare two results: 1490891661.074981

Objective-C, How can I get the current date in UTC timezone?

筅森魡賤 提交于 2019-12-29 10:27:30
问题 I am trying: NSDate *currentDateInLocal = [NSDate date]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'"]; NSString *currentLocalDateAsStr = [dateFormatter stringFromDate:currentDateInLocal]; NSDateFormatter * dateFormatter2 = [[NSDateFormatter alloc] init]; NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"]; [dateFormatter2 setTimeZone:timeZone]; [dateFormatter2 setDateFormat:@"yyyy-MM-dd'T'HH:mm:SS.SSS'Z'

How to minimize the costs for allocating and initializing an NSDateFormatter?

纵然是瞬间 提交于 2019-12-29 07:37:06
问题 I noticed that using an NSDateFormatter can be quite costly. I figured out that allocating and initializing the object already consumes a lot of time. Further, it seems that using an NSDateFormatter in multiple threads increases the costs. Can there be a blocking where the threads have to wait for each other? I created a small test application to illustrate the problem. Please check it out. http://github.com/johnjohndoe/TestNSDateFormatter git://github.com/johnjohndoe/TestNSDateFormatter.git

NSDateFormatter dateFromString Always Returns nil

六月ゝ 毕业季﹏ 提交于 2019-12-28 06:31:06
问题 I want to apologize ahead of time for asking a repeat question, but none of the other solutions have worked for me yet. Every time I try to pass a date string to the dateFromString function I get nil. I haven't read anywhere that things have changed since the iOS 7 update, but I am current on updates if that makes a difference on whether or not this still works the same way. This is the code I'm using to create the date from string: NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]

NSDateFormatter with 24 hour times

我们两清 提交于 2019-12-28 02:49:06
问题 I have a countdown timer which countsdown from the current date/time to a specific future date/time. It is working great except for one problem. I input the future date using NSDateFormatter and dateFromString . It doesn't seem to be able to accept any time (hour) over 12 though indicating it is not support 24 hour clock. Is there a way to enable 24 hour clock support or a workaround? Here is some of my code: NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateFormat:@"yyyy-MM-dd