Marshall Mathers wrote:So, what I'd like to ask for, is for you to give me some tips on how to for example, after declaring all the date parameters, i.e. that the Assignment is due for 23/11/2016 at 23:59, I am able to retrieve the day, the month, the minute, etc. individually.
Winston Gutkowski wrote:
That is probably not the most recent version; if you plan to let any of your code loose on an unsuspecting world, you should update your Java® installation. I would go for 8u73/74.
Marshall Mathers wrote:. . . I'm using [JDK]1.7.9 . . .
Knute Snortum wrote:I think SimpleDateFormat will work in this situation, but in Java 7 it's a little convoluted.
I'm happy to explain more, but first I'd like to see what you can do with what I've given and the Java docs. Post your code here.
Knute Snortum wrote:If you're going to use Java 8, then things change -- they actually get easier.
* Create a DateTimeFormatter with the static ofPattern(PATTERN) method.
* Create a LocalDateTime object with the static parse(DATE_STRING, FORMATTER) method.
* Retrieve data from the LocalDateTime object, e.g. getYear().
* Your date format string is close. If the String to parse is "23/11/2016 at 23:59", the formatter should be "dd/MM/yyyy 'at' HH:mm". The single quote (') surrounds a literal.
Knute Snortum wrote:You should use the parse() method of LocalDateTime. Assuming your date string is in a variable called dateString...
Some rules to keep in mind:
a. None of the fields should be blank.
b. Any year fields must be a four digit number (i.e. greater than 999) and
less than or equal to 2016.
c. Any month field should be a number between 1 and 12 inclusive.
d. Any day field should be a number between 1 and 31 inclusive where
the month is January (1), March (3), May (5), July (7), August (8),
October (10), and December (12), between 1 and 30 inclusive where
the month is April (4), June (6), September (9), and November (11),
and between 1 and 28 for February (2). We are ignoring leap years for
e. The hour should be a number between 0 and 23 inclusive.
f. The minute should be a value between 0 and 59 inclusive
Knute Snortum wrote:java.lang.CharSequence is a good guess for the type of dateString, but it can just be a String.
This is assuming that you're setting the date string yourself. Posting your latest code will help with the context.
What I'm asking from you is to (if possible) tell me where I'm going wrong and why when I start up the program, I can't add a new assignment, etc.