0
timestamp = "2016-07-22 19:00:01.001+00";

I have above string and I want get 27 May 19:00

let formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
formatter.dateFromString(timestamp)
3
  • i need two string 27 May and 19:00 from above foramt Commented Jun 17, 2016 at 11:28
  • 07-22 is actually 22 Jul Commented Jun 17, 2016 at 11:32
  • How can he get this , ignore May Jul. Commented Jun 17, 2016 at 11:35

1 Answer 1

2

Use date format like this,

formatter.dateFormat = "dd MMM HH:mm"

OR

In your case you can get by writing like below,

let timestamp = "2015-07-27 19:29:50 +0000"
let formatter = NSDateFormatter()
formatter.timeZone = NSTimeZone(name: "UTC")
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z"
let date = formatter.dateFromString(timestamp)
formatter.dateFormat = "dd MMM HH:mm"
let st = formatter.stringFromDate(date!)
print(st)

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

You shouldn't set the timezone, using the correct timezone date format x "yyyy-MM-dd HH:mm:ss.sssx" will take care of it
Your timestamp is different from OP's one, so I don't see how you answer their question?

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.