CSharp examples for System:DateTime Hour
This method returns a two digit hour for the date given.
using System.IO;// ww w. jav a2s . com using System.Text; using System.Linq; using System.Collections.Generic; using System; public class Main{ #endregion #region GetTwoDigitHour(DateTime date) /// <summary> /// This method returns a two digit hour for the date given. /// </summary> /// <param name="date"></param> /// <returns></returns> public static string GetTwoDigitHour(DateTime date) { // initial value string twoDigitHour = ""; // set the twoDigitHour twoDigitHour = date.Hour.ToString(); // if the Length is less than two if (twoDigitHour.Length < 2) { // prepend a zero to the Hour twoDigitHour = "0" + date.Hour.ToString(); } // return value return twoDigitHour; } }