deadManN deadManN - 1 year ago 110
Java Question

Java Calendar/Date Minvalue Supported on DB/Rest

I'm using Spring Boot, and HSQLDB file,
When i use:

calendar.setTime(new Date(Long.MIN_VALUE));

and and store the model,

after i call rest client, i get invalid date, when i check it, it returns some positive value instead of negative one :| what should i use as min_Value.

i thought it may be SQL issue, i changed temporary variable type from timespan to Date, but didn't worked again, i no longer sure what is the case of this issue, and what nuber i should use, every one talk about min value, some one talked about around -8.......L too that work in JS, but it didn't worked here too :|

Answer Source

Avoid ancient date-time values

Many reasons to not use that minimum number as a date value. As commented, standard SQL does not permit such ancient dates. No database implementation I know of supports that value. And using a date-time for historical values is fraught with problems and issues, and ill-advised.

Use epoch as a flag value

If you are looking for an arbitrary value to use as a flag such as "no value intended" while avoiding the use of nulls, then I suggest using the Java and Unix epoch of first moment of 1970 in UTC. If you know your system will never store any date-time that far back as a valid value, this will work well. And 1970-01-01T00:00:00Z is easily recognized by many programmers, DBAs, and SysAdmins as the common epoch and therefore likely to be a special value.


Avoid using the Date and Calendar classes. These troublesome classes and their siblings are now legacy, supplanted by the java.time classes.

These classes include a constant for that epoch value: Instant.EPOCH

Similar Question: Minimum date in Java

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download