Paul Clapham wrote:And is it really necessary to pass the timestamp to that method in two separate parts? If you're stuck with that, then the first thing you should do inside the method is to combine them into a single string which looks like "11/01/2020 05:05 PM". Then you can easily create a pair of formatters to transform that to the SQLite standard form.
Campbell Ritchie wrote:No, you are creating two different objects and when you create the second you are discarding the first.
Mark Richardson wrote:. . . //apparently, I can have one or the other... I can't set time and date separately . . .
Which Date class are you using? You know how useless java.util.Date is? Remember that it comes with setXXX() methods which you can probably use for what you want. Find out some 21st century date classes: look here in the Java™ Tutorials.
If you want a String, why not use a class designed for manipulating Strings: this, for example.
Junilu Lacar wrote:You don't even have to use regular expressions for this.
The convert() method would also report any errors it finds but those would be violations of whatever formatting rules you choose to implement rather than illegal numerals.
Carey Brown wrote:If you want to be even more robust you can look for patterns of 4 or more of any of those characters that appear consecutively, which should never happen. Example: "VIIII".
Now with that pattern you DO want to use find() because you don't care where in the string the pattern occurs.
Junilu Lacar wrote:We could speculate and debate about what is and isn't valid but since we haven't heard from OP since the opening post, I don't think any of it matters until we hear what his requirements are. On the subject of clear requirements for this problem, this article might be of interest: https://dzone.com/articles/roman-numerals-kata-tdd-and
Junilu Lacar wrote: See if you can understand what this does: