About the time zone design
Crape Myrtle Live Li Wanhong
Because the system uses different geography, time zone and time are different, therefore, the time zone processing needs to be designed to ensure that the system time is correct. Each site's time zone is specified by the user, time is saved with a string in the local time zone, with the time zone converted to local time, and the time zone used by the terminal is the local time zone. In most countries, daylight saving time is used, so when you use daylight savings, add t_timezone time zone timezone to 1, and when daylight saving time ends, the T_timezone timezone timezone minus 1.
A Select the time zone feature.
The user selects the country and then the system detects all time zones of the country from the configuration file, selected by the user. The selected time zone key is saved in the T_site timezone field, in T_timezone save its time zone, country, key. The country's time zone has information. When the daylight saving time is over, the user clicks on a button and the system saves the end of the period. At the end of daylight saving time, it will be reduced by 1 hours, so there will be one hours of repetition, such as 3 points to 2 points, there will be 2 2 to 3 points of time period. It is necessary to distinguish between the next 2 and 3 points for this one hours, by setting the Timezoneoffset for this hour to 1, and then using it later. Timezoneoffset defaults to 0. The beginning and end of daylight saving time in general countries is fixed, for example, the first Sunday 2 o'clock in March, the first Sunday of November ends at 3, and in most countries daylight saving is different.
Time-related tables have timezoneoffset fields, and at the end of daylight saving time, the Timezoneoffset is set to 1 for the one-hour repetition. When you later access the Date field of the table, you need to query the time of the end of daylight saving from the Daylight saving time table, and if you use it in this repeating period of time, it is distinguished by the Timezoneoffset field.
To do this, a new daylight saving time table T_dst_end will be added to save this area.
Two Select the function of the time.
1. Server time
With Dateutils. formatcurrentdate ("gmt+0" ), get Standard time. Show this time call string FormatCurrentDate2 (string date, "gmt+0");
2. User interface setup time.
The time selected by the interface is local time, saved in the database as a string, and can be obtained later using this time, using the Call date gettimefromstring (string date, String countryto) to get local time, The parameter countryto is the local time zone, which displays this time call to String formatcurrentdate (Date date,string countryto), or string FormatCurrentDate2 (string Date,string Countryto);
Using the Gettimefromstring (StringDate, String countryto) method, regardless of the time zone, the result is a time of String date.
3.schedule of time.
The hour can be called by the date intgethour (String countryfrom,string date), similar to the month date, time division seconds number, convenient comparison processing.
Three Use the time method.
Date processing Tool class Dateutils has been modified, each method adds the time zone parameter in the parameter Stringcountryfrom, later use needs to add this parameter.
After the user login, the system selects the time zone from the interface, the time zone key into the T_site table, the country, time zone and key into the T_timezone, the system uses the time zone according to T_site Key from T_timezone to query out the time zone TimeZone.
2015-3-2
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
About the time zone design