Note kettle Scripts 生成Date数据

//Create a Locale according to the specified language code

var locale = new java.util.Locale(language_type.getString(),country_code.getString());

//Create a calendar, use the specified initial date

var calendar = new java.util.GregorianCalendar(locale);

calendar.setTime(initial_date.getDate());

calendar.add(calendar.DAY_OF_MONTH,DaySequence.getInteger()-1);

//get calendar date

var date=new java.util.Date(calendar.getTimeInMillis());

//example:3/9/2020

var date_short=java.text.DateFormat.getDateInstance(java.text.DateFormat.SHORT,locale).format(date);

//example:Mar 9,2020

var date_medium=java.text.DateFormat.getDateInstance(java.text.DateFormat.MEDIUM,locale).format(date);

//example:March 9,2020

var date_long=java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG,locale).format(date);

//example:Monday March 9,2020

var date_full=java.text.DateFormat.getDateInstance(java.text.DateFormat.FULL,locale).format(date);

//day in year

var simpleDateFormat=java.text.SimpleDateFormat("D",locale);

var day_in_year=simpleDateFormat.format(date);

//day in month

simpleDateFormat.applyPattern("d");

var day_in_month=simpleDateFormat.format(date);

//day_name

simpleDateFormat.applyPattern("EEEE");

var day_name=simpleDateFormat.format(date);

//example Mon

simpleDateFormat.applyPattern("E");

var day_abb=simpleDateFormat.format(date);

//week in year

simpleDateFormat.applyPattern("WW");

var week_in_year=simpleDateFormat.format(date);

//week in month

simpleDateFormat.applyPattern("W");

var week_in_month=simpleDateFormat.format(date);

//month num

simpleDateFormat.applyPattern("MM");

var month_num=simpleDateFormat.format(date);

//month_en

simpleDateFormat.applyPattern("MMMM");

var month_name=simpleDateFormat.format(date);

//month_nameS "Mar"

simpleDateFormat.applyPattern("MMM");

var monthname_s=simpleDateFormat.format(date);

//2 digit representation of the year, example: "20" for 2020

simpleDateFormat.applyPattern("y");

var year2=simpleDateFormat.format(date);

//year4 "2020"

simpleDateFormat.applyPattern("yyyy");

var yearn=simpleDateFormat.format(date);

//quarter

var quarter_name="Q";

var quarter_number;

switch(parseInt(month_num)){

case 1:case 2:case 3:quarter_number="1";break;

case 4:case 5:case 6:quarter_number="2";break;

case 7:case 8:case 9:quarter_number="3";break;

case 10:case 11:case 12:quarter_number="4";break;

}

quarter_name +=quarter_number;

//get the local yes/no values

var yes=local_yes.getString();

var no=local_no.getString();

//initialize for week calculations

var first_day_of_week=calendar.getFirstDayOfWeek();

var day_of_week=java.util.Calendar.DAY_OF_WEEK;

//find out if this is the first day of week

var is_first_day_in_week;

if(first_day_of_week==calendar.get(day_of_week)){

is_first_day_in_week=yes;

}else{

is_first_day_in_week=no;

}

//calculate the next day

calendar.add(calendar.DAY_OF_MONTH,1);

//get the next calendar date

var next_day=new java.util.Date(calendar.getTimeInMillis());

//find out if this is the last day of the week

var is_last_day_of_week;

if(first_day_of_week==calendar.get(day_of_week)){

is_last_day_in_week=yes;

}else{

is_last_day_in_week=no;

}

//find out if this the first day of th month

var is_first_day_in_month;

if(day_in_month==1){

is_first_day_in_month=yes;

}else{

is_first_day_in_month=no;

}

//find out if this the last day of th month

var is_last_day_in_month;

if(java.text.SimpleDateFormat("d",locale).format(next_day)==1){

is_last_day_in_month=yes;

}else{

is_last_day_in_month=no;

}

//date = year4 + "-" + month_number + "-" + day_in_month

var year_quarter            = yearn + "-" + quarter_name;

var year_month_number      = yearn + "-" + month_num;

var year_month_jian = yearn + "-" + monthname_s;

var date_key = yearn + month_num + (day_in_month<10?"0":"") + day_in_month;


你可能感兴趣的:(Note kettle Scripts 生成Date数据)