Does MySQL support historical date (like 1200)?

前端 未结 7 1440
一整个雨季
一整个雨季 2020-11-30 11:18

I can\'t see any info about that. Where can I find the oldest date Mysql can support ?

相关标签:
7条回答
  • 2020-11-30 11:58

    This is an important and interesting problem which has another solution.

    Instead of relying on the database platform to support a potentially infinite number of dates with millisecond precision, rely on an object-oriented programming language compiler and runtime to correctly handle date and time arithmetic.

    It is possible to do this using the Java Virtual Machine (JVM), where time is measured in milliseconds relative to midnight, January 1, 1970 UTC (Epoch), by persisting the required value as a long in the database (including negative values), and performing the required conversion/calculation in the component layer after retrieval.

    For example:

    Date d = new Date(Long.MIN_VALUE);
    DateFormat df = new SimpleDateFormat("EEE, d MMM yyyy G HH:mm:ss Z");
    System.out.println(df.format(d));
    

    Should show: Sun, 2 Dec 292269055 BC 16:47:04 +0000

    This also enables independence of database versions and platforms as it abstracts all date and time arithmetic to the JVM runtime, i.e. changes in database versions and platforms will be much less likely to require re-implementation, if at all.

    0 讨论(0)
提交回复
热议问题