Get Date Time Info - CSharp System

CSharp examples for System:DateTime Time

Description

Get Date Time Info

Demo Code


using System.Globalization;
using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/* w ww  .j  a va  2s  . c  o  m*/

public class Main{
        public static string GetDateTimeInfo(DateTime oDateTime)
        {
            StringBuilder oSB = new StringBuilder();

            oSB.AppendLine("    Date: " + oDateTime.Date.ToString());
            oSB.AppendLine("    Ticks: " + oDateTime.Ticks.ToString());
            oSB.AppendLine("    Kind: " + oDateTime.Kind.ToString());
            oSB.AppendLine("    IsDaylightSavingTime: " + oDateTime.IsDaylightSavingTime().ToString());

            oSB.AppendLine("    Month: " + oDateTime.Month.ToString());
            oSB.AppendLine("    Day: " + oDateTime.Day.ToString());
            oSB.AppendLine("    Year: " + oDateTime.Year.ToString());
            oSB.AppendLine("    DayOfYear: " + oDateTime.DayOfYear.ToString());
            oSB.AppendLine("    DayOfWeek: " + oDateTime.DayOfWeek.ToString());

            oSB.AppendLine("    TimeOfDay: " + oDateTime.TimeOfDay.ToString());
            oSB.AppendLine("    Hour: " + oDateTime.Hour.ToString());
            oSB.AppendLine("    Minute: " + oDateTime.Minute.ToString());
            oSB.AppendLine("    Second: " + oDateTime.Second.ToString());
            oSB.AppendLine("    Millisecond: " + oDateTime.Millisecond.ToString());

            oSB.AppendLine("    ToBinary: " + oDateTime.ToBinary().ToString());
            oSB.AppendLine("    ToFileTime: " + oDateTime.ToFileTime().ToString());
            oSB.AppendLine("    ToFileTimeUtc: " + oDateTime.ToFileTimeUtc().ToString());
            oSB.AppendLine("    ToLocalTime: " + oDateTime.ToLocalTime().ToString());
            oSB.AppendLine("    ToLongDateString: " + oDateTime.ToLongDateString().ToString());
            oSB.AppendLine("    ToLongTimeString: " + oDateTime.ToLongTimeString().ToString());
            oSB.AppendLine("    ToOADate: " + oDateTime.ToOADate().ToString());
            oSB.AppendLine("    ToShortDateString: " + oDateTime.ToShortDateString().ToString());
            oSB.AppendLine("    ToShortTimeString: " + oDateTime.ToShortTimeString().ToString());
            oSB.AppendLine("    ToString: " + oDateTime.ToString().ToString());
            oSB.AppendLine("    ToUniversalTime: " + oDateTime.ToUniversalTime().ToString());

            oSB.AppendLine("    TimeZoneInfo.Local.IsInvalidTime: " + TimeZoneInfo.Local.IsInvalidTime(oDateTime));
            oSB.AppendLine("    TimeZoneInfo.Local.IsAmbiguousTime: " + TimeZoneInfo.Local.IsAmbiguousTime(oDateTime));
            oSB.AppendLine("    TimeZoneInfo.Local.IsDaylightSavingTime: " + TimeZoneInfo.Local.IsDaylightSavingTime(oDateTime));

            oSB.AppendLine("    TimeZoneInfo.Utc.IsAmbiguousTime: " + TimeZoneInfo.Utc.IsAmbiguousTime(oDateTime));
            oSB.AppendLine("    TimeZoneInfo.Utc.IsDaylightSavingTime: " + TimeZoneInfo.Utc.IsDaylightSavingTime(oDateTime));
            oSB.AppendLine("    TimeZoneInfo.Utc.IsInvalidTime: " + TimeZoneInfo.Utc.IsInvalidTime(oDateTime));

            return oSB.ToString();
        }
}

Related Tutorials