A simple method for saving time information in MySQL
This article mainly introduces MySQL to save time information on the simple method, the content of the article is carefully selected and edited by the author, with a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the MySQL save time information on the simple method.
The solution reference is as follows, that is, based on the SimpleDateFormat object, you need to be clear about the time zone that you currently need to use.
SimpleDateFormat.setTimeZone (TimeZone)
/ / Java:long timeMs = System.currentTimeMillis (); System.out.println ("long =" + timeMs); / / current time zoneSimpleDateFormat default = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); System.out.println (default.format (timeMs)); / / + 8:00 time zoneSimpleDateFormat chinaFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); chinaFormat.setTimeZone (TimeZone.getTimeZone ("GMT+8:00")); System.out.println ("GMT+8:00 =" + chinaFormat.format (timeMs)) / / + 5:30 time zoneSimpleDateFormat indiaFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); indiaFormat.setTimeZone (TimeZone.getTimeZone ("GMT+5:30")); System.out.println ("GMT+5:30 =" + indiaFormat.format (timeMs))
Using the above method can actually solve the time zone problem, because I obtained the statistics through the hour table and the hour table is one record per hour. While the Indian time zone is GMT+5:30, there will be a half-hour data deviation on the basis of the current table structure, so in order to solve this problem, we modify the statistical granularity of the hour table to half an hour.
Summary:
The blog simply states the key solution to the time zone, and the premise of using this solution is that the international timestamp is stored in the database!
Only time storage based on absolute timestamp, there is no time zone problem at all! Time zone is just a display problem!
After reading the above simple methods of saving time information on MySQL, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.