Dustin Ward wrote:All that being said, how should I design my class in a way that their input can be stored easily? Should I make individual fields like: String month, int day, int year and then write the code to limit what their input can be
Dustin Ward wrote:Anyway, sorry if this is a stupid question, design always trips me up in the beginning.
Roel De Nijs wrote:
Dustin Ward wrote:All that being said, how should I design my class in a way that their input can be stored easily? Should I make individual fields like: String month, int day, int year and then write the code to limit what their input can be
Don't use separate fields for date and time! You probably want to use a DATETIME column in your database table. Or maybe two columns: beginTime and endTime perhaps.
If you are using Java 8 for your application, there is no need to use JodaTime, simply use the new Date/Time API, which is a part of the SDK (and thus you need no external library dependency). If you are using Java 7 (or prior), you could use Calendar and Date classes, or add an additional library (like JodaTime). But it might be time to consider upgrading to Java 8.
Dustin Ward wrote:Anyway, sorry if this is a stupid question, design always trips me up in the beginning.
There are no stupid questions! In fact, thinking about a (good) design before starting to code right away will probably save you tons of work and refactorting
Carey Brown wrote:Your statement
System.out.println(dateTime);
will use the default format which is an international standard which includes the 'T'.
Dustin Ward wrote:I do get a 'T' in the middle of my output though, which is weird...
Dustin Ward wrote:Ohhhh. Well, it actually works when I insert it into mysql table using DATETIME so I am cool with it
Roel De Nijs wrote:
Dustin Ward wrote:I do get a 'T' in the middle of my output though, which is weird...
No, that's not weird at all. It is just the textual (string) representation of a LocalDateTime instance as explained in the toString() method.
Dustin Ward wrote:Ohhhh. Well, it actually works when I insert it into mysql table using DATETIME so I am cool with it
Of course it will work when inserting it into a MySQL database table, because the textual representation is not used in the MySQL driver to insert/updata a DATETIME column. It only offers some information about the object in (hopefully) a human-readible format.
Dustin Ward wrote:How and where would I overwrite the LocalDateTime .toString? Like, I've overwritten all of my CLASS' toString's but how do I just overwrite a random objects?
Because I would really like to print it off without the T and although I elected the military time, I'd like to write it out in standard 1-12 time without making people specify AM or PM when I get their input
Dustin Ward wrote:How and where would I overwrite the LocalDateTime .toString? Like, I've overwritten all of my CLASS' toString's but how do I just overwrite a random objects?
Dustin Ward wrote:Woohoo! Nevermind. I figured it out.
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|