Using the Javadate class Data Warehouse dimension table

Source: Internet
Author: User
Tags dateformat locale

Using the Javadate class Data Warehouse dimension table

Date Category:

, returns the number of milliseconds for a relative date. Accurate to milliseconds. However, the internationalization and sub-timezone display of dates is not supported.

The date class began to evolve from the Java Development Package (JDK) 1.0, when it included only a few ways to get or set the various parts of a date data. Like months, days, and years. These methods have now been criticized and moved to the Calendar class, which is designed to better handle the internationalized format of date data.

Calender class:

The time class, which is more powerful relative to date, is an abstract class that provides general date churn and internationalization support.

GregorianCalendar class:

Provides methods for working with dates. Used to calculate the date. is a subclass of the Calendar class, and it is practical to have a way to infer a leap year.

DateFormat class:

can accept string input and output. Provides the ability to format date/time information.

SimpleDateFormat class:

A more powerful date-time formatting class that defines its own formatting date and time.

Java.util.Locale class:

Describe a particular geographical, political, and cultural area. Locale objects mainly encapsulate the two aspects of "region" and "language type".


The following code simulates some of the field values that are used to generate a 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)); }}

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

Using the Javadate class Data Warehouse dimension table

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.