marciokoko
marciokoko

Reputation: 4986

Why does NSDate() store a strange value in CoreData

I am using NSDate() to store now date into CoreData:

    sampleSwim.date = NSDate()

where sampleSwim is an NSManagedObject backed by a class auto generated from xcdatamodeld file. In that model date is a Date type. In the NSManagedObject class it shows up as NSDate.

For some reason Im getting back this value:

2014-10-297 05:07:57

Ive got quite a few samples of that already. This is from the console. Why would this happen?

This is how Im logging it (and reading it):

var myWorkout: Swim = self.workouts[indexPath!.row] as Swim
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "YYYY-MM-DD hh:mm:ss"
let date = dateFormatter.stringFromDate(myWorkout.date as NSDate)
println(date)

Thanks

Upvotes: 0

Views: 652

Answers (1)

rintaro
rintaro

Reputation: 51911

You should use this format:

dateFormatter.dateFormat = "yyyy'-'MM'-'dd HH':'mm':'ss"
  • DD is "Day of year"
  • hh is 12 hours format
  • YYYY is "Week of Year" based.

Here is the document: Date Format Patterns

Upvotes: 1

Related Questions