Questions tagged [nsdateformatter]
Class that creates string representations of NSDate (and NSCalendarDate) objects, and convert textual representations of dates and times into NSDate objects.
2,934
questions
0
votes
2
answers
35
views
Reload SwiftUI view when DateFormatter format updates?
Related to forcing an update, I would like SwiftUI to reload and update my content view when a DateFormatter instance's format property changes.
Example:
private extension String {
enum ...
0
votes
0
answers
14
views
Android app Matter integration - not able to connect the device
I am trying to run the google sample POC for the matter with the module ESP32, sharing the url link which I am referring to is here.
But I am not able to stablish the connection, intermittent call ...
0
votes
0
answers
34
views
Mock simulator / device time format setting
There was a bug within our app where if the user set their time format in settings to the 24-Hour Time format, the time would not show up as desired, which is always in the 12 hour format with am/pm.
...
0
votes
1
answer
106
views
Convert datetime to string in sql
Using SQL language , trying to pull the same dates as you can see from the code as below;
select aa.sim
from app_date1 aa
left join
app_date2 bb on aa....
0
votes
0
answers
37
views
why this date formatter not working correctly?
facing the following issue:
I'm try to create a date by adding 2 strings one with a date "23/06/2023" and one is the time "21:00"
why I'm getting this strange result:
see my ...
0
votes
0
answers
509
views
Capture of 'dateFormatter' with non-sendable type 'ISO8601DateFormatter' in a `@Sendable` closure
I have the following code
let dateFormatter = ISO8601DateFormatter()
dateFormatter.formatOptions.insert(.withFractionalSeconds)
decoder.dateDecodingStrategy = .custom({ decoder in
...
1
vote
1
answer
33
views
Converting NSString into NSDate in objective c for mention Date String
I am trying to convert DateString into Different DateFromat.
strDate = @"24-08-2022 06:38:50 +0:00"
NSDateFormatter *dateformate = [[NSDateFormatter alloc] init];
[...
0
votes
1
answer
67
views
Convert Int to date formatter followed with timezone
Trying to convert Int to formatted string date with supplied timezone value and formatter to expected result "12/01/2022 09:03:41 PM THA".
//Response Data.
{
"code": "...
0
votes
0
answers
24
views
Swift - Problem converting year + weekOfYear components to Date [duplicate]
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yy/MM/dd"
let d = dateFormatter.date(from: "2022/12/15")!
// First block (as expected)
let compsYearMonth = ...
1
vote
1
answer
44
views
Getting difference between two dates like in facebook, instagram comment section
I am working on an app in which i have to display the date/time difference between current date and posted date in format like "1 hour ago", "4 days ago"
I got api response in this ...
0
votes
1
answer
88
views
Convert Int To Date Formatter value
Below code I used to convert Int to Time.
//MARK: - Convert Date To String
func dateToString(date: Date, dateFormat: String) -> String {
let dateFormater = DateFormatter()
dateFormater....
0
votes
1
answer
85
views
How to convert a date to a specific timezone when user is in a different timezone?
I have a problem in handling dates in Swift in different timezones. I'm getting an Italian date from my server and I'm trying to convert it into a Date through the following function:
func ...
0
votes
0
answers
16
views
Swift String to Date conversion from youtube API publishedAt [duplicate]
I need to convert this date string to a date object. This is the format that youtube API sends for a published at date.
2022-10-26T02:40:04.645878Z
let all_time_date = "2022-10-26T02:40:04....
0
votes
1
answer
36
views
How to get the date with specific hour and minute of today from "HH:mm" string in Objecive-C
I have a time string like "HH:mm" format and I want to get a NSDate object of today at that time.
I am using NSDateFormatter but it not work.
Here is my code:
NSString *dateString = @"...
0
votes
0
answers
265
views
iOS Swift app - 24 hour format from Settings app is not respected for Germany and France
I have to display date and time in an iOS app based on locale (Region) and time format (24-Hour vs 12-Hour) set in the device Settings app.
I am using below code for the same :-
class func ...
0
votes
1
answer
89
views
Converting Python time.asctime() to Swift Date using DateFormatter
I am working with a series of string representations of timestamps returned by time.asctime() in Python. The documentation states:
Convert a tuple or struct_time representing a time as returned by ...
0
votes
0
answers
55
views
Swift Convert String to Date
I have a string with time in it "20:52" and I am trying to use DateFormatter to convert it to Date.
My code is:
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale.current
...
0
votes
0
answers
196
views
iOS: 24 hour time formatting not honored with Region=Canada, Language=French
If Language is French and Region is Canada, the Languge & Region pane in Settings shows 24 hour time formatting in the sample area as expected, as does the rest of iOS and stock apps.
But if I ...
1
vote
0
answers
371
views
iOS: Date formatter with "ar_AE" language code not converting date to Arabic
When I try to convert date to Arabic language with below code & ar_AE language code, it shows date in western numerals not in Arabic.
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = ...
0
votes
1
answer
52
views
IOS ObjC NSDateFormatter stringFromDate returns nil
I have a function that takes 2 parameters, a date string in format @"2022-09-19T18:00:00.000Z", and a pattern (date format): @"MMM d".
The problem is that the date is always nil, ...
-2
votes
2
answers
806
views
Swift: Converting string to date [duplicate]
I have a date as String but I want to convert it to Date.
The date in string looks like this - "2022-09-09T07:00:00.0000000".
Code to convert it to Date:
public static func dateStringToDate(...
0
votes
0
answers
83
views
datefromstring always return nil on physical device objective c
I have to show app build date in the project. In "dd MMM yyyy" format.
GetBuildDate {
NSString *buildDate;
// Get build date and time, format to 'yyMMddHHmm'
NSString *dateStr = ...
1
vote
1
answer
61
views
DateTime2 formart conversion to Swift Date
I have a date string coming from back-end as "2022-08-16T13:44:11.8743234". Date formatting and conversion is the oldest skill in the book but I cannot figure out why I'm unable to convert ...
-3
votes
1
answer
43
views
iOS-Swift How to convert a String of Date to another String of Date [closed]
I have this String "Aug 15, 2022". How can I convert it to "Monday, August 15, 2022"
1
vote
1
answer
790
views
DateFormatter returns previous day
I've looked around and people have had problems with different years, random and changing results, and nil dates, but nothing like what I have, so I am asking here. Note I am in Playground right now.
...
0
votes
0
answers
205
views
Wrong date in client ios device in Thailand different from my device in India
I am receiving the date as a string from the server via rest API and changing the format of that string. For this, I am converting string to date and then converting date back to string back to date ...
-1
votes
2
answers
75
views
Swift - iOS Unable to convert to required date format
I am using date picker in my application. After selects particular date, It's not able to converting to required format.
Datepicker date:
2021-07-21 13:53:38 +0000
expected format
21 July 2021
I ...
0
votes
2
answers
105
views
How can I convert date string to time string?
I have a string that looks like this:
"date": "2022-06-30T02:15:00.000+07:00"
And I formatted it to convert to "HH:mm" like this:
func formatTime(string: String) -> ...
-1
votes
3
answers
94
views
DateFormatter showing incorrect time
My requirement is to convert date string (in PHT) received from my API to another date string format.
API Date String format: "MM/dd/yyyy HH:mma" eg. "06/28/2022 06:55PM"
UI Date ...
1
vote
1
answer
437
views
Swift date formatter off by one day [duplicate]
It's pretty bizarre. If I look at the Data object it correctly has 01/01/1990, but when converting it to a string it returns 12/31/1989. This seems to have only recently started happening as the code ...
0
votes
1
answer
170
views
DateComponentsFormatter - same dates, different results
Why is dateRemainingText2 giving different result from dateRemainingText?
Obviously dateRemainingText2 is wrong.
Here's my code:
import Foundation
let startDate = Calendar.current.date(from: ...
1
vote
1
answer
278
views
Can I make RelativeDateTimeFormatter display more units such year, month and day?
Here's my code:
let startDate = Calendar.current.date(from: DateComponents(year: 2022, month: 5, day: 1)) ?? .now
let endDate = Calendar.current.date(from: DateComponents(year: 2020, month: 6, day: 2))...
1
vote
1
answer
33
views
ios NSDateFormatter transform date result error
my code is as fllow:
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = "yyyy-MM-dd";
fmt.timeZone = NSTimeZone.systemTimeZone;
NSString *selfStr = [fmt ...
0
votes
1
answer
450
views
Applying timezone offset data provided by OpenWeatherMap (Swift)
Getting the current day, hour, minute etc for the users current location is fairly straight forward using a function like this, so long as you have UTC data:
func getHourForDate(_ date: Date?)-> ...
0
votes
0
answers
45
views
Fireebase Crashlitics -[NSDateFormatter _setDateFormat:alreadyLocked:]
I get
-[NSDateFormatter _setDateFormat:alreadyLocked:]
in my Firebase Crashlytics,
How it caused and how to fix it?
Is it a thread-safety issue?
1
vote
1
answer
256
views
Properly ordering month and date according to locale
I want to display start and end date of week in a human readable format. Using MMMM d as date format base. For example:
- March 7 - 13
- February 28 - March 6
- 7-13 de marzo
So if week start and end ...
1
vote
2
answers
5k
views
Timezone in swift [duplicate]
I am struggling quite a bit with dates. I have the following code:
Current Date in Amsterdam: 22-Februari-2022 - 11:40
Current Date in New York: 22-Februari-2022 - 05:40
The dateBoughtString goes in ...
0
votes
1
answer
69
views
Date Formatter unexpected output
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.dateFormat = "MMMM dd, yyyy 'at' HH:mm:ss aa z"
dateFormatter.amSymbol = &...
0
votes
2
answers
114
views
how to get time difference form formatted time string values
Hi how to get time difference for two sting value
startTime = "09:00 AM"
EndTime = "05:30 PM"
func timeDifferenceBetweenTwoTime(startTime: String, endTime:String) ->CGFloat{
...
-3
votes
1
answer
299
views
How to convert 10digit int to date [closed]
How to convert 1640704675 into date.
extension Date {
var millisecondsSince1970:Int64 {
return Int64((self.timeIntervalSince1970 * 1000.0).rounded())
}
init(milliseconds:Int64) {
...
-4
votes
1
answer
461
views
Formatting a Date and Time in Swift [closed]
I have this time format 2022-01-09T19:04:16 obtained from an API. I would like to show a readable time from this string and also, possibly the difference from given time and current time.
I cannot ...
0
votes
1
answer
164
views
Issue Decoding Child Models as Properties with JSONDecoder?
Any clue why my decoding is not working properly? I've created 3 models: Portfolio, Tokens, and Holdings, and for some reason Holdings is causing issues, not sure if it's the structure, but here's the ...
0
votes
0
answers
19
views
NSDateFormatter.dateFromString returns nil when changing phone settings [duplicate]
I am trying to convert a string into Date in iOS (Swift/Objective C) but I have an issue when the date contains the hours in 24 formats like 2018-11-24_18-11-10
The issue is that when the phone uses ...
0
votes
0
answers
266
views
NSDateFormatter dateFromString crash (in call from formatter.date(from: String)
I'm getting a crash reported on my call to date(from:) on my formatter:
guard let date = DateFormatter.longYearFormatter(timeZone: timeZone).date(from: dateString) else { return }
dateString here is ...
-2
votes
1
answer
327
views
Swift date formatter wrongfully converting/creating dates/strings [duplicate]
Greetings there m'ladies, m'lords!
Long story short I have a helper struct where I have some helper functions for creating date formatters, Date objects and String representations of dates.
I've ...
0
votes
1
answer
107
views
Parsing Date JSON Crash in UK region
I am downloading json with a date string. An example is "2020-06-08T09:48:47.570"
I am easily able to convert this string into a date with a DateFormatter and a dateFormat of "yyyy-MM-...
1
vote
2
answers
204
views
How to know Date format getting from sever [duplicate]
I am trying to get date format of a date that I am getting from server.
What will be the format of this date:
2021-10-14T17:53:03.753588+05:30
What I tried:
yyyy-MM-dd'T'HH:mm:ssXXX
But Its not ...
0
votes
1
answer
240
views
Issue with determining if time format is 12 hours or 24 hours
In my AppDelegate's applicationWillEnterForeground(_), I have the below code to determine if the device is set to 12 hour or 24 hour time format.
func applicationWillEnterForeground(_ application: ...
0
votes
1
answer
80
views
DateFormatter does NOT convert specific dates (Swift)
I have the below code on playground and app and DateFormatter are returning nil just for the date "1990-10-21":
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "YYYY-MM-...
-3
votes
1
answer
92
views
How to convert date from dd/MM to dd/MM/yyyy? [duplicate]
I have to change the format of the date from dd/MM to dd/MM/yyyy and I use this code
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM"
let date = dateFormatter.date(from:...