| | |
| | | /// <returns>时间</returns> |
| | | public static DateTime? ToDateTime(this object obj) |
| | | { |
| | | if (obj != null && DateTime.TryParse(obj.ToString(), out var date) && date != DateTime.MinValue) |
| | | if (obj != null && DateTime.TryParse(obj.ToString(), out var date) && date != DateTime.MinValue && date != DateTimeOffset.MinValue) |
| | | { |
| | | return date; |
| | | } |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取年龄 |
| | | /// </summary> |
| | | /// <param name="birthday"></param> |
| | | /// <returns></returns> |
| | | public static int? GetAge(this DateTime? birthday) |
| | | { |
| | | if (birthday == null) return null; |
| | | var age = DateTime.Now.Year - birthday.Value.Year; |
| | | if (birthday.Value.Date > DateTime.Today.AddYears(-age)) |
| | | { |
| | | age--; |
| | | } |
| | | return age; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取时间范围选择器 |
| | | /// </summary> |
| | | /// <param name="str"></param> |