Get the 3-digit string representation of the day (e.g."003") - CSharp System

CSharp examples for System:DateTime

Description

Get the 3-digit string representation of the day (e.g."003")

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w w  w .j a va2 s . co  m

public class Main{
        /// <summary>
        /// Get the 3-digit string representation of the day (e.g."003")
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        public static string GetThreeDigitDayString(int day)
        {
            if (day <= 0)
                return null;
            else if (day < 10)
                return "00" + day;
            else if (day < 100)
                return "0" + day;
            else if (day <= 366)
                return day.ToString();
            else
                return null;
        }
}

Related Tutorials