To Casual Range - CSharp System

CSharp examples for System:DateTime Format

Description

To Casual Range

Demo Code

// Copyright (c)2008-2011 Mark II Software, LLC.  All Rights Reserved.
using System.Text;
using System.Collections.Generic;
using System;/*from   www. j a v  a2s. com*/

public class Main{
        public static string ToCasualRange(this DateTime dt, DateTime dtEnd)
		{
			String ret = dt.ToCasual() + " - " + dtEnd.ToCasual();
			return ret;
		}
        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();
		}
}

Related Tutorials