将object类型转换成时间,如果能转的话。

   1:  //将object类型转换成时间,如果能转的话。
   2:  protected DateTime GetDataTime(object obj) 
   3:  { 
   4:      if (obj == null) 
   5:      { 
   6:          return DateTime.Now; 
   7:      } 
   8:      else 
   9:      { 
  10:          DateTime time = DateTime.Now; 
  11:          bool isConvertSeccess = DateTime.TryParse(obj.ToString(), out time); 
  12:          //若是转换成功,time中就是转换的值,若失败,则变成日期初始化值。
  13:          if (isConvertSeccess) 
  14:              return time; 
  15:          else 
  16:              return DateTime.Now; 
  17:      } 
  18:  }
原文地址:https://www.cnblogs.com/pnljs/p/2959683.html