예제 #1
0
 /// <summary>
 /// 将日期对象转换为数字,如:"yyyyMMdd",当对象为空或转换错误时丢出InvalidCastException
 /// </summary>
 /// <param name="obj">日期</param>
 /// <returns>int日期对象转换后的数字</returns>
 public static int ParseDateToIntEx(object obj)
 {
     return(ParseDateToInt(ParseHelper.Parse <DateTime>(obj)));
 }
예제 #2
0
 /// <summary>
 /// 将日期对象转换为数字,如:"yyyyMMdd"
 /// </summary>
 /// <param name="obj">日期</param>
 /// <param name="defaultVal">转换错误的默认值</param>
 /// <returns>日期对象转换后的数字</returns>
 public static int ParseDateToInt(object obj, DateTime defaultVal)
 {
     return(ParseDateToInt(ParseHelper.Parse <DateTime>(obj, defaultVal)));
 }
예제 #3
0
 /// <summary>
 /// 根据格式要求取得日期字符串,当对象为空或转换错误时丢出InvalidCastException
 /// </summary>
 /// <param name="obj">日期</param>
 /// <param name="format">格式字符串</param>
 /// <returns>特定格式的日期字符串</returns>
 public static string ParseDateToStrEx(object obj, string format)
 {
     return(ParseHelper.Parse <DateTime>(obj).ToString(format));
 }
예제 #4
0
 /// <summary>
 /// 取得日期数字,如:"yyyyMMdd"
 /// </summary>
 /// <param name="date">日期</param>
 /// <returns>日期数字</returns>
 public static int ParseDateToInt(DateTime date)
 {
     return(ParseHelper.Parse <int>(date.ToString(BaseConstants.DEFAULT_SHORTDATETIME_FORMAT)));
 }
예제 #5
0
 /// <summary>
 /// 根据格式要求取得日期字符串
 /// </summary>
 /// <param name="obj">日期</param>
 /// <param name="defaultVal">转换错误的默认值</param>
 /// <param name="format">格式字符串</param>
 /// <returns>传入格式的日期字符串,转换过程中发生错误则返回传入的默认值</returns>
 public static string ParseDateToStr(object obj, DateTime defaultVal, string format)
 {
     return(ParseHelper.Parse <DateTime>(obj, defaultVal).ToString(format));
 }