Java tutorial
/* * @(#)CommonDataHandleUtil.java $version 2011. 4. 11. * * Copyright 2007 NHN Corp. All rights Reserved. * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package com.nbp.nmp.benefit.common; import java.util.Date; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.FastDateFormat; import com.nbp.nmp.category.CategoryVO; /** * ? ? ? */ public class CommonDataHandleUtil { /** * categoryBig, categoryMiddle, categorySmall, categoryDetail? key * ?? ? Map? . * @param categoryVO * @return Map<String, Object> */ public static Map<String, Object> getCategoryNameForViewMap(CategoryVO categoryVO) { Map<String, Object> targetMap = new HashMap<String, Object>(); String[] fullCategoryName = categoryVO.getWholeCategoryName().split(">"); if (categoryVO.getLevel() > 0) { targetMap.put("categoryBig", fullCategoryName[0]); } if (categoryVO.getLevel() > 1) { targetMap.put("categoryMiddle", fullCategoryName[1]); } if (categoryVO.getLevel() > 2) { targetMap.put("categorySmall", fullCategoryName[2]); } if (categoryVO.getLevel() > 3) { targetMap.put("categoryDetail", fullCategoryName[3]); } return targetMap; } /** * ? ? ? * @param date * @param fromFormatString * @param toFormatString * @return */ public static String stringDateFormatter(String date, String fromFormatString, String toFormatString) { String[] fromParttern = { fromFormatString }; FastDateFormat toFormatter = FastDateFormat.getInstance(toFormatString); Date fromDate = null; try { fromDate = DateUtils.parseDate(date, fromParttern); } catch (Exception e) { return ""; } return toFormatter.format(fromDate); } /** * ? ? ? ? * @param date * @param format * @return */ public static String dateFormatter(Date date, String format) { if (date == null) { return ""; } FastDateFormat toFormatter = FastDateFormat.getInstance(format); return toFormatter.format(date); } /** * ?? date ? * ? ?? ?? "yyyyMMdd" * @param dateString * @param dateFormat * @return */ public static Date stringToDate(String dateString, String dateFormat) { if (dateFormat == null) { dateFormat = "yyyyMMdd"; } String[] parttern = { dateFormat }; try { return DateUtils.parseDate(dateString, parttern); } catch (Exception e) { return null; } } }