nsdate

Convert UTC NSDate into Local NSDate not working

霸气de小男生 提交于 2020-07-23 05:28:04
问题 I have a string getting from server as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" I convert this string into NSDate by this formate. class func convertUTCDateToLocateDate(dateStr:String) -> NSDate{ let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" dateFormatter.timeZone = NSTimeZone(name: "UTC") let date = dateFormatter.dateFromString(dateStr) dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" dateFormatter.timeZone = NSTimeZone.localTimeZone() let

Convert UTC NSDate into Local NSDate not working

▼魔方 西西 提交于 2020-07-23 05:27:45
问题 I have a string getting from server as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" I convert this string into NSDate by this formate. class func convertUTCDateToLocateDate(dateStr:String) -> NSDate{ let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" dateFormatter.timeZone = NSTimeZone(name: "UTC") let date = dateFormatter.dateFromString(dateStr) dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" dateFormatter.timeZone = NSTimeZone.localTimeZone() let

Convert UTC NSDate into Local NSDate not working

北慕城南 提交于 2020-07-23 05:26:21
问题 I have a string getting from server as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" I convert this string into NSDate by this formate. class func convertUTCDateToLocateDate(dateStr:String) -> NSDate{ let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" dateFormatter.timeZone = NSTimeZone(name: "UTC") let date = dateFormatter.dateFromString(dateStr) dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" dateFormatter.timeZone = NSTimeZone.localTimeZone() let

Convert UTC NSDate into Local NSDate not working

人走茶凉 提交于 2020-07-23 05:26:21
问题 I have a string getting from server as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" I convert this string into NSDate by this formate. class func convertUTCDateToLocateDate(dateStr:String) -> NSDate{ let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" dateFormatter.timeZone = NSTimeZone(name: "UTC") let date = dateFormatter.dateFromString(dateStr) dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z" dateFormatter.timeZone = NSTimeZone.localTimeZone() let

Swift: Get correct time zone from Date Picker?

和自甴很熟 提交于 2020-05-28 04:48:18
问题 I am trying to get the correct time zone from the date picker in swift using time formatter, it's not working. I'm getting UTC, not EST. 1) If I print dateFormatter.stringFromDate(datePicker) I get EST, but 2) I don't need a string, I need an NSDate in EST so 3) I can use it to get the timeIntervalSinceDate(NSDate) in EST. My trick of trying to take it from string back to NSDate as seen below didn't work. It's still in UTC and the time interval since date is not right. dateFormatter.locale =

Convert from UTC to local timezone give wrong result

烂漫一生 提交于 2020-05-09 11:55:22
问题 Background I need to convert time string with format: "HH:mm" from UTC to local timezone. For example if UTC time is 09:00, local time (Stockholm/Europe) should be two hours ahead. Problem When I convert 09:00 (UTC) to Stockholm/Europe time I get 10:00. It should be 11:00. func UTCToLocal(date:String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") let dt = dateFormatter.date(from: date) dateFormatter

Convert from UTC to local timezone give wrong result

别等时光非礼了梦想. 提交于 2020-05-09 11:55:10
问题 Background I need to convert time string with format: "HH:mm" from UTC to local timezone. For example if UTC time is 09:00, local time (Stockholm/Europe) should be two hours ahead. Problem When I convert 09:00 (UTC) to Stockholm/Europe time I get 10:00. It should be 11:00. func UTCToLocal(date:String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "HH:mm" dateFormatter.timeZone = TimeZone(abbreviation: "UTC") let dt = dateFormatter.date(from: date) dateFormatter

Use Swift's Date with CoreData

心已入冬 提交于 2020-04-08 09:16:26
问题 I have a lot of date fields in my database model. CoreData allows to use NSDate or TimeInterval to save dates depending on "Use Scalar Type" option. However both these options are bad for me since I want to use dates as Date objects. Since NSDate is not implicitly convertible to Date I have to cast/convert values to Date or to implement a lot of custom setters/getters in my NSManagedObject classes. I have tried to use ValueTransformer but it does not work with non-@objc classes like Date . So

Use Swift's Date with CoreData

↘锁芯ラ 提交于 2020-04-08 09:15:33
问题 I have a lot of date fields in my database model. CoreData allows to use NSDate or TimeInterval to save dates depending on "Use Scalar Type" option. However both these options are bad for me since I want to use dates as Date objects. Since NSDate is not implicitly convertible to Date I have to cast/convert values to Date or to implement a lot of custom setters/getters in my NSManagedObject classes. I have tried to use ValueTransformer but it does not work with non-@objc classes like Date . So

NSDateFormatter not working properly?

心不动则不痛 提交于 2020-03-16 11:18:20
问题 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