nsdateformatter

Dateformatter issue in swift

青春壹個敷衍的年華 提交于 2021-02-19 09:05:19
问题 My API sending me date string in UTC like 2/20/2016 11:45 AM. For displaying date in my timezone, I am converting date from UTC to Local time zone like below code let sourceDateString = "12/20/2016 11:45 AM" let formatter = DateFormatter() formatter.dateFormat = "MM/dd/yyyy hh:mm a" formatter.timeZone = TimeZone(identifier: "UTC") let date = formatter.date(from: sourceDateString) print(date) formatter.timeZone = NSTimeZone.local formatter.dateFormat = "MMM dd,yyyy hh:mm a" let strDate =

Dateformatter issue in swift

让人想犯罪 __ 提交于 2021-02-19 09:03:51
问题 My API sending me date string in UTC like 2/20/2016 11:45 AM. For displaying date in my timezone, I am converting date from UTC to Local time zone like below code let sourceDateString = "12/20/2016 11:45 AM" let formatter = DateFormatter() formatter.dateFormat = "MM/dd/yyyy hh:mm a" formatter.timeZone = TimeZone(identifier: "UTC") let date = formatter.date(from: sourceDateString) print(date) formatter.timeZone = NSTimeZone.local formatter.dateFormat = "MMM dd,yyyy hh:mm a" let strDate =

How to convert this UNIX epoch date in milliseconds to local date/time?

…衆ロ難τιáo~ 提交于 2021-02-10 16:11:45
问题 I am getting something strange date/time from server. How to convert "notification_date": 1500461137000, to local time format. 回答1: This is a UNIX epoch date in milliseconds. You can convert it with timeIntervalSince1970 after dividing it by 1000. let localDate = Date(timeIntervalSince1970: notificationDate / 1000) 回答2: Do an extension on Double and convert from your notification date. Double(notificationDate).convertEpochTime() ... extension Double { func convertEpochTime() -> String{ let

Date formatter for a certain format of date

你离开我真会死。 提交于 2021-02-08 07:33:51
问题 I might missing something, but I can't compose proper date formatter string for the date: 2016-01-14T10:24:26+0000 What is 'T' here? and how to include timezone? My string does not work: @"yyyy-MM-dd'T'hh:mm:ss Z" 回答1: You have to use 'T' in single quotes like below format to retrive string ftom date: yyyy-MM-dd'T'hh:mm:ssZ Let me know. 回答2: NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; dateFormatter.dateFormat = @"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"; NSDate *yourDate =

How to format a LocalTime variable

萝らか妹 提交于 2021-02-05 12:36:25
问题 I am quite new to Java windowbuilder, and this is part of my first project. String starttime = JOptionPane.showInputDialog(null, "What time would you like to start your revision ? (ie:12:24) "); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); LocalTime start = LocalTime.parse(starttime,dtf); I want to convert the format of start from ("HH:mm:ss..etc") to ("HH:mm") , but I get an error for the LocalTime.parse for some reason. Any suggestions what I should do. I'm using Joda Time

How to format a LocalTime variable

北慕城南 提交于 2021-02-05 12:33:33
问题 I am quite new to Java windowbuilder, and this is part of my first project. String starttime = JOptionPane.showInputDialog(null, "What time would you like to start your revision ? (ie:12:24) "); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); LocalTime start = LocalTime.parse(starttime,dtf); I want to convert the format of start from ("HH:mm:ss..etc") to ("HH:mm") , but I get an error for the LocalTime.parse for some reason. Any suggestions what I should do. I'm using Joda Time

Date Formatting Returns Nil [duplicate]

半腔热情 提交于 2021-02-05 12:28:59
问题 This question already has answers here : I get nil when using NSDateFormatter in swift (2 answers) Closed 4 years ago . I'm getting nil when trying to create a date from a string. What am I doing wrong? let createdAt = passesDictionary["createdAt"] as? String print(createdAt) let dateFormatter = NSDateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd" let createdDate = dateFormatter.dateFromString(createdAt!) print(createdDate) createdAt is Optional("2016-05-03T19:17:00.434Z"), but

Get difference between two dates?

前提是你 提交于 2021-02-05 12:13:11
问题 I have two dates in 24 hours formate like (dd-MMM-yyyy HH:mm). I want to get a difference between these two dates. My Code : This is getting only dates, I want a number of days and remaining time in hours also. (like 6days 5 hours) NSTimeInterval secondsBetween = [date2 timeIntervalSinceDate:date1]; int numberOfDays = secondsBetween / 86400; NSLog(@"There are %d days in between the two dates.", numberOfDays); 回答1: NSDateComponentsFormatter can do that NSTimeInterval secondsBetween = [date2

Convert Date with +1000 values

对着背影说爱祢 提交于 2021-01-29 08:54:44
问题 I have a date like this : 2018-04-30T23:22:05+1000 and want to convert in to Date Object let formatter = DateFormatter() formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss:Z" // z, zz also still nil let ss = formatter.date(from: "2018-04-30T23:22:05+1000") print("VAL : \(ss)") // nil always What is the correct format for +1000 values? Also what locale i have to add to get exact date? 回答1: use your dateformat as zone - The long specific non-location format. Where that is unavailable, falls back to

How to add th and st in Date Format

独自空忆成欢 提交于 2021-01-27 07:35:50
问题 I want to convert the date like "Friday 17th, 7:00pm" this format. but I am unable to add "th" and "st" after the date. I am using below code to convert the date format like this. please tell me. What I do for this format? func convertDateFormater(_ date: String) -> String { let dateFormatter = DateFormatter() dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"//this your string date format dateFormatter.timeZone = NSTimeZone(name: "UTC") as TimeZone? //dateFormatter.locale = Locale