Use the java date class to generate a data warehouse dimension table

Source: Internet
Author: User

Use the java date class to generate a data warehouse dimension table

Use the java date class to generate a data warehouse dimension table

Date class:

Returns the number of milliseconds of a relative date. Accurate to milliseconds, but does not support date internationalization and Time Zone display. The Date class evolved from the Java Development Kit (JDK) 1.0. At that time, it only contained several methods for obtaining or setting each part of a Date data, such as months, days, and years. These methods have now been criticized and moved to the Calendar class, an improvement designed to better process the international format of date data.

Calender class:

A more powerful time class than Date is an abstract class that provides regular Date modification and international support.

GregorianCalendar class:

A date processing method is provided for date calculation. It is a subclass of the Calendar class and a useful method for determining a leap year.

DateFormat class:

Supports string input and output, and supports formatting date/time information.

SimpleDateFormat class:

More powerful Date and Time formatting class, custom format date and time.

Java. util. Locale class:

Describe a specific geographic, political, and cultural region. The Locale object mainly encapsulates "region" and "language type.


The following code is used to generate some field values of the 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)                                     .format(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.DAY_OF_WEEK) ? "yes" : "no";         }                 publicstatic void main(String[] args) {                   DateUtild = new DateUtil();                   d.calAndShow();                   System.out.println(Math.ceil(11.0/3.0));         }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.