How to get the current time as datetime

Update for Swift 3: let date = Date() let calendar = Calendar.current let hour = calendar.component(.hour, from: date) let minutes = calendar.component(.minute, from: date) I do this: let date = NSDate() let calendar = NSCalendar.currentCalendar() let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date) let hour = components.hour let minutes = components.minute See the same question … Read more

Best way to store date/time in mongodb

The best way is to store native JavaScript Date objects, which map onto BSON native Date objects. > db.test.insert({date: ISODate()}) > db.test.insert({date: new Date()}) > db.test.find() { “_id” : ObjectId(“…”), “date” : ISODate(“2014-02-10T10:50:42.389Z”) } { “_id” : ObjectId(“…”), “date” : ISODate(“2014-02-10T10:50:57.240Z”) } The native type supports a whole range of useful methods out of the … Read more