CSharp examples for System:DateTime Format
Formats the specified source. Deals with null DateTime
using System;//from w ww .j a v a 2 s . c o m public class Main{ /// <summary> /// Formats the specified source. /// Deals with null DateTime /// </summary> /// <param name="source">The source.</param> /// <param name="format">The format.</param> /// <returns></returns> public static string SafeFormat(this DateTime? source, string format) { if (source == null || !source.HasValue || string.IsNullOrEmpty(format)) return string.Empty; return source.Value.ToString(format); } }