通用日期处理函数,日期处理大全[9]

[入库:2005年8月19日] [更新:2007年3月25日]

本文简介:选择自 netcom19 的 blog

   theformat = getoradatetimeformat();
  }
  else
  {
   theformat = getoradateformat();
  }
  return tostring( thedate, theformat );
 }

 /**
  * 将日期对象转换成为指定日期、时间格式的字符串形式。如果日期对象为空,返回 一个空字符串对象,而不是一个空对象。
  *
  * @param thedate
  *            将要转换为字符串的日期对象。
  * @param hastime
  *            如果返回的字符串带时间则为true
  * @return 转换的结果
  */
 public static synchronized string tostring( date thedate, boolean hastime )
 {
  /**
   * 详细设计:
   * 1.如果有时间,则设置格式为getdatetimeformat的返回值
   * 2.否则设置格式为getdateformat的返回值
   * 3.调用tostring(date thedate, dateformat thedateformat)
   */
  dateformat theformat;
  if ( hastime )
  {
   theformat = getdatetimeformat();
  }
  else
  {
   theformat = getdateformat();
  }
  return tostring( thedate, theformat );
 }

 /**
  * 标准日期格式
  */
 private static final simpledateformat date_format = new simpledateformat(
  "mm/dd/yyyy" );
 /**
  * 标准时间格式
  */
 private static final simpledateformat date_time_format = new simpledateformat(
  "mm/dd/yyyy hh:mm" );
 /**
  * 带时分秒的标准时间格式
  */
 private static final simpledateformat date_time_extended_format = new simpledateformat(
  "mm/dd/yyyy hh:mm:ss" );
 /**
  * ora标准日期格式
  */
 private static final simpledateformat ora_date_format = new simpledateformat(
  "yyyymmdd" );
 /**
  * ora标准时间格式
  */
 private static final simpledateformat ora_date_time_format = new simpledateformat(
  "yyyymmddhhmm" );
 /**
  * 带时分秒的ora标准时间格式
  */
 private static final simpledateformat ora_date_time_extended_format = new simpledateformat(
  "yyyymmddhhmmss" );

 /**
  * 创建一个标准日期格式的克隆
  *
  * @return 标准日期格式的克隆
  */
 public static synchronized dateformat getdateformat()
 {
  /**
   * 详细设计: 1.返回date_format
   */
  simpledateformat thedateformat = ( simpledateformat )
   date_format.clone();
  thedateformat.setlenient( false );
  return thedateformat;
 }

 /**
  * 创建一个标准时间格式的克隆
  *
  * @return 标准时间格式的克隆
  */
 public static synchronized dateformat getdatetimeformat()
 {
  /**
   * 详细设计: 1.返回date_time_format
   */
  simpledateformat thedatetimeformat = ( simpledateformat ) date_time_format
   .clone();
  thedatetimeformat.setlenient( false );
  return thedatetimeformat;
 }

 /**
  * 创建一个标准ora日期格式的克隆
  *
  * @return 标准ora日期格式的克隆
  */
 public static synchronized dateformat getoradateformat()
 {
  /**
   * 详细设计: 1.返回ora_date_format
   */
  simpledateformat thedateformat = ( simpledateformat ) ora_date_format
   .clone();
  thedateformat.setlenient( false );
  return thedateformat;
 }

 /**
  * 创建一个标准ora时间格式的克隆
  *
  * @return 标准ora时间格式的克隆
  */
 public static synchronized dateformat getoradatetimeformat()
 {
  /**
   * 详细设计: 1.返回ora_date_time_format
   */
  simpledateformat thedatetimeformat = ( simpledateformat )
   ora_date_time_format.clone();
  thedatetimeformat.setlenient( false );
  return thedatetimeformat;
 }

 /**
  * 将一个日期对象转换成为指定日期、时间格式的字符串。 如果日期对象为空,返回一个空字符串,而不是一个空对象。
  *
  * @param thedate
  *            要转换的日期对象
  * @param thedateformat
  *            返回的日期字符串的格式
  * @return 转换结果
  */
 public static synchronized string tostring( date thedate,
  dateformat thedateformat )
 {
  /**
   * 详细设计:
   * 1.thedate为空,则返回""
   * 2.否则使用thedateformat格式化
   */
  if ( thedate == null )
   return "";

本文关键:通用日期处理函数,日期处理大全
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top