Search code examples
validationcocoacore-datauser-input

Users will enter dates in my cocoa (core data) app. How to choose right date format?


I am working on my first application for mac which uses Core Data. Since I don't have much software development experience I would like to ask the more experienced developers the following question:

When entering data in some of the forms, user will have to enter a date in couple of the forms. Since app will be on app store and people from different continents will download it (I hope so) I am thinking of allowing the user to select his preferred date format from the preferences panel that I have in my app.

But I am wondering what will happen if after entering 500 or more records, he decide to change the date format again? Will that cause a mess in core data eventually?

Is this good idea or I should keep things simple and just get the system date (user computer date format) and use that date format? What would you do? Any advice will be deeply appreciated.


Solution

  • My advice is to keep date as timeinterval. You can see such method for NSDate.

    The interval between the date object and 00:00:00 UTC on 1 January 1970.
    

    So if you get NSDate object from NSDatFormatter object you will be able to obtain time in seconds since 1970. You could store this value in Core Data and use it later for creating NSDate objects. You will be able to use it for different locales and time zones as well as use the correct format. 'Dates' is complex topic and I suggest you to read guides about dates and date formatters.