CSharp examples for System:DateTime Format
To Casual
// Copyright (c)2008-2011 Mark II Software, LLC. All Rights Reserved. using System.Text; using System.Collections.Generic; using System;/*w ww . j av a 2s. com*/ public class Main{ public static string ToCasual(this DateTime dt) { StringBuilder sb = new StringBuilder(); bool pm = dt.Hour >= 12; int hour = dt.Hour; if (pm && hour > 12) { hour -= 12; } else if (hour == 0) { hour = 12; } sb.Append(hour); if (dt.Second > 0 || dt.Minute > 0) { sb.AppendFormat(":{0:00}", dt.Minute); if (dt.Second > 0) sb.AppendFormat(":{0:00}", dt.Second); } sb.Append(pm ? "pm" : "am"); return dt.ToString("ddd MMM dd, yyyy") + " at " + sb.ToString(); } }