开发者

Best way to store date/time into core data

开发者 https://www.devze.com 2022-12-24 13:12 出处:网络
For each course I am storing the day of the week the class the user has...and the start and end time and room no.

For each course I am storing the day of the week the class the user has...and the start and end time and room no. What would be the best approach in terms of data type, Like for storing tim开发者_JAVA百科e?? so that when I pull it out I can display it e.g 1:00 PM.

Thanks!


Use a date attribute in your managed object model for each time you want to store. See the section on "Dates and Times" in the Core Data Programming Guide.


If its an actual date e.g. Tuesday, December 15th 2010 1:00pm CST, then you can use a data attribute.

However, if it's just a generic time of day e.g. any given Wednesday at 1:00pm, the you will need to create attributes to hold the day, the time and meridian as strings and or numbers.

I would recommend creating a entity in the model just for this information and then setting a relationship to it.

Pseudocode:

DayAndTimeEntity{
    weekdayName = sting;
    timeOfDay = string or number; //use a number if you need to do calculations
    isAM = BOOL;
}

in use, "any Monday at 1:00pm" would look like:

aDayAndTimeEntityInstance{
    weekdayName = "Monday";
    timeOfDay = "1:00" 
    isAM = NO;
}

Then set a relationship to any other entities that need to store this time. You can elaborate on the basic idea as needed.


Date Type should work

0

精彩评论

暂无评论...
验证码 换一张
取 消