0

I need to encode the time stamp in my url from 03-28-2017 11:00:05 +0000 to this format 01-01-1970%2000%3A00%3A00%20%2B0530.

I am using this code:

updateCheckUrl = updateCheckUrl.addingPercentEncoding(withAllowedCharacters:  NSCharacterSet.urlQueryAllowed)

But the result is not as expected its just adding %20 in the spaces. How can i get the desired encoding using swift 3.1.

2
  • what is your desired encoding ? Commented May 24, 2017 at 11:27
  • Neither of the default encodings is suitable to encode parameters! You should take the queryAllowed and remove &=+. Commented May 24, 2017 at 12:43

2 Answers 2

1
let str = "03-28-2017 11:00:05 +0000"
let encode = str.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) 
print(encode) // 03-28-2017%2011:00:05%20+0000
Sign up to request clarification or add additional context in comments.

Comments

1
var allowedCharacters = CharacterSet.urlQueryAllowed
allowedCharacters.remove(charactersIn: "!*'();:@&=+$,/?%#[]")

let paramValue = "03-28-2017 11:00:05 +0000"
let encodedValue = paramValue.addingPercentEncoding(withAllowedCharacters: allowedCharacters) ?? ""
print(encodedValue)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.