Generating a Data Warehouse dimension table using the Java date class
Date class:
The most basic date-time class that returns the number of milliseconds for a relative date. Accurate to milliseconds, but does not support the internationalization and sub-timezone display of dates. The date class began to evolve from the Java Development Package (JDK) 1.0, when it contained only a few methods of acquiring or setting up parts of a date data, such as month, day, and year. These methods have now been criticized and moved to the Calendar class, which is designed to better handle the internationalization of date data formats.
Calender class:
The time class, which is more powerful relative to date, is an abstract class that provides general date modification and internationalization support.
GregorianCalendar class:
Provides methods for processing dates, which are used to calculate dates, are subclasses of the Calendar class, and it is useful to have a method for judging leap years.
DateFormat class:
You can accept string input, output, and provide the ability to format date/time information.
SimpleDateFormat class:
A more powerful date-time formatting class that customizes the date and time of the formatting.
Java.util.Locale class:
Describing specific geographic, political, and cultural regions, the locale object mainly encapsulates "region" and "language type".
The following code simulates some of the field values in the resulting date dimension table:
Import Java.text.simpledateformat;import Java.util.calendar;import Java.util.date;import Java.util.gregoriancalendar;import Java.util.Locale; public class Dateutil {localeloc = new locale ("zh", "cn");//Localeloc = new locale ("en", "cn"); Calendarcalendar = new GregorianCalendar (LOC); Publicvoid init () {Calendar.set (2014,9, 10); } publicdate Add (int day) {calendar.add (calendar.day_of_month,day); Returncalendar.gettime (); } publicvoid showdate (date date) {p ("Timeinmillis", Calendar.gettimeinmillis () + ""); P ("ShortDate", Java.text.DateFormat.getDateInstance (Java.text.dateformat.short,loc) . Format (date)); P ("Mediumdate", Java.text.DateFormat.getDateInstance (Java.text.dateformat.medium,loc). Format (date)); P ("Longdate", Java.text.DateFormat.getDateInstance (Java.text.DateFormat.LONG, loc) . Format (date)); P ("Longfull", Java.text.DateFormat.getDateInstance (Java.text.DateFormat.FULL, loc). For Mat (date)); SIMPLEDATEFORMATSDF = new SimpleDateFormat ("D", loc); P ("Dayin Year", Sdf.format (date)); Sdf.applypattern ("D"); P ("Dayin Month", Sdf.format (date)); Sdf.applypattern ("eeee"); P ("Dayname", Sdf.format (date)); Sdf.applypattern ("E"); P ("Dayabbreviation", Sdf.format (date)); Sdf.applypattern ("ww"); P ("Weekin Year", Sdf.format (date)); Sdf.applypattern ("W"); P ("Weekin Month", Sdf.format (date)); Sdf.applypattern ("MM"); String month = Sdf.format (date); P ("MonthNumber", Sdf.format (date)); Sdf.applypattern ("MMMM"); P ("MonthName", Sdf.format (date)); Sdf.applypattern ("MMM"); P ("Monthabbreviation", Sdf.format (date)); Sdf.applypattern ("yy"); P ("Year2", Sdf.format (date)); Sdf.applypattern ("yyyy"); P ("Year4", Sdf.format (date)); Intquarter_number = (int) Math.ceil ((Integer.parseint (month)/3.0)); P ("Quertername", "Q" +quarter_number); Intfirst_day_of_week = Calendar.getfirstdayofweek (); P ("Is_first_day_of_week", Firstweekday (First_day_of_week)); } publicvoid P (String desc,string date) {System.out.println (desc+ ":" + date); } publicvoid Calandshow () { for (int i = 0; i < 3; i++) {init (); Showdate (Add (i)); System.out.println (); }} publicstring firstweekday (int first) {Returnfirst = = Calendar.get (calendar.d Ay_of_week)? "Yes": "No"; } publicstatic void Main (string[] args) {dateutild = new dateutil (); D.calandshow (); System.out.println (Math.ceil (11.0/3.0)); }}
Generating a Data Warehouse dimension table using the Java date class