Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-11618] Cast from string to Date with DateFormatter using current locale doesn't work #3381

Open
swift-ci opened this issue Oct 15, 2019 · 2 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-11618
Radar None
Original Reporter JoseASantiago (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: 57f5eae704b844d8a7a5da504be769a3

Issue Description:

I'm trying to cast a String with a proper format and using the current locale for the DateFormatter and it fails the cast, it only works if I hard code a locale.

where 
string = "2019-11-30 11:59:59.0" 
format: "yyyy-MM-dd HH:mm:ss.S"   
 func stringToDate(_ string: String, format: String) -> Date?
    {
        let dateStringFormatter = DateFormatter()
        dateStringFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.S"
        dateStringFormatter.timeZone = TimeZone.current
        dateStringFormatter.locale = Locale.current
        let date = dateStringFormatter.date(from: string)
        
        
        return date//dateStringFormatter.date(from: string)
    }
@belkadan
Copy link

To be clear, are you using Linux or Apple Foundation?

@swift-ci
Copy link
Contributor Author

Comment by Jose Santiago (JIRA)

Apple Foundation

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants