例: 日付変換

この例では、日付を mm/dd/yy の形式から月、日、年の形式に変換します。例えば、6/12/2004 は June 12, 2004 に変換されます。この例では、ビジネス・ロジックが呼び出される前にグローバル変数 theDate が設定されていることを前提としています。この例では、以下のメソッドをどのように使用して入力変数の値を取得しているかに注意してください。

IGlobalVariable inputDate = getGlobalVariable(blInfo, "theDate");

この例では、標準の Java™ 関数を使用して日付を希望の形式で表示するようにストリングを操作した後で、以下のメソッドを使用して同じグローバル変数に新規ストリングを組み込んでいます。

setGlobalVariable(blInfo, "theDate", formattedDate);

////////////////////////////////////////////////////////////////////////////////
//  This sample is provided AS IS.
//  Permission to use, copy and modify this software for any purpose and
//  without fee is hereby granted. provided that the name of IBM not be used in
//  advertising or publicity pertaining to distribution of the software without
//  specific written permission.
//
//  IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SAMPLE, INCLUDING ALL
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL IBM
//  BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
//  DAMAGES WZIETransOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
//  IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
//  OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SAMPLE.
////////////////////////////////////////////////////////////////////////////////
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.ibm.hats.common.IBusinessLogicInformation;
import com.ibm.hats.common.GlobalVariable;
import com.ibm.hats.common.IGlobalVariable;

public class CustomDateFormatter
{
 		public static void execute(IBusinessLogicInformation blInfo)
			{
				IGlobalVariable inputDate = getGlobalVariable(blInfo, "theDate");
				SimpleDateFormat inputFormat = new SimpleDateFormat("MM/dd/yyyy");
				SimpleDateFormat outputFormat = new SimpleDateFormat("MMMM dd, yyyy");
       		
				try 
					{
						Date tempDate = inputFormat.parse(inputDate.getString().trim()); 
						String formattedDate = outputFormat.format(tempDate); 
						setGlobalVariable(blInfo, "theDate", formattedDate);
					} 
						catch (ParseException ex) 
							{
								ex.printStackTrace();
							}
			}
}