logo

C#의 날짜/시간

C#에서 날짜와 시간을 처리해야 하는 경우 DateTime을 사용했습니다.

DateTime의 속성과 메서드를 사용하여 날짜와 시간의 형식을 다양한 형식으로 지정할 수 있습니다./p>

DateTime의 값은 0001년 1월 1일 자정 12:00:00부터 서기 9999년 12월 31일 오후 11:59:59 사이입니다.

여기서는 C#에서 DateTime을 생성하는 방법을 설명합니다.

DateTime 객체를 생성하는 방법에는 여러 가지가 있습니다. DateTime 객체에는 시간, 문화, 날짜, 현지화, 밀리초가 있습니다.

여기에는 DateTime 객체를 생성하기 위해 DateTime 구조에서 사용하는 다양한 생성자를 보여주는 코드가 있습니다.

 // From DateTime create the Date and Time DateTime DOB= new DateTime(19, 56, 8, 12, 8, 12, 23); // From String creation of DateTime string DateString= '8/12/1956 7:10:24 AM'; DateTime dateFromString = DateTime.Parse(DateString, System.Globalization.CultureInfo.InvariantCulture); Console.WriteLine(dateFromString.ToString()); // Empty DateTime DateTime EmpDateTime= new DateTime(); // Just date DateTime OnlyDate= new DateTime(2002, 10, 18); // DateTime from Ticks DateTime OnlyTime= new DateTime(10000000); // Localization with DateTime DateTime DateTimewithKind = new DateTime(1976, 7, 10, 7, 10, 24, DateTimeKind.Local); // DateTime with date, time and milliseconds DateTime WithMilliseconds= new DateTime(2010, 12, 15, 5, 30, 45, 100); 

C#의 DateTime 속성

DateTime에는 날짜 및 시간 속성이 있습니다. DateTime에서 날짜와 시간을 확인할 수 있습니다. DateTime에는 시, 분, 초, 밀리초, 연도, 월, 일과 같은 다른 속성도 포함되어 있습니다.

DateTime의 다른 속성은 다음과 같습니다.

  1. DayOfWeek 속성의 도움으로 요일의 이름을 얻을 수 있습니다.
  2. 올해의 날짜를 얻으려면 DayOfYear 속성을 사용합니다.
  3. DateTime에서 시간을 얻으려면 TimeOfDay 속성을 사용합니다.
  4. Today 속성은 오늘의 값을 갖는 DateTime의 객체를 반환합니다. 시간 값은 12:00:00입니다.
  5. Now 속성은 현재 날짜와 시간을 포함하는 DateTime 개체를 반환합니다.
  6. DateTime의 Utc 속성은 UTC(협정 세계시)를 반환합니다.
  7. 하나의 틱은 DateTime의 100나노초를 나타냅니다. DateTime의 Ticks 속성은 DateTime의 틱 수를 반환합니다.
  8. Kind 속성은 현지 시간인 UTC(협정 세계시)를 기반으로 인스턴스에서 시간 표현이 수행되는 값을 반환합니다. 또한 지정되지 않은 기본값도 표시됩니다.

여기서는 C# 코드에서 DateTime의 속성을 사용하는 예를 살펴보겠습니다.

예:

 using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateTimeProperty = new DateTime(1974, 7, 10, 7, 10, 24); Console.WriteLine('Day:{0}', DateTimeProperty.Day); Console.WriteLine('Month:{0}', DateTimeProperty.Month); Console.WriteLine('Year:{0}', DateTimeProperty.Year); Console.WriteLine('Hour:{0}', DateTimeProperty.Hour); Console.WriteLine('Minute:{0}', DateTimeProperty.Minute); Console.WriteLine('Second:{0}', DateTimeProperty.Second); Console.WriteLine('Millisecond:{0}', DateTimeProperty.Millisecond); Console.WriteLine('Day of Week:{0}', DateTimeProperty.DayOfWeek); Console.WriteLine('Day of Year: {0}', DateTimeProperty.DayOfYear); Console.WriteLine('Time of Day:{0}', DateTimeProperty.TimeOfDay); Console.WriteLine('Tick:{0}', DateTimeProperty.Ticks); Console.WriteLine('Kind:{0}', DateTimeProperty.Kind); } } } 

산출:

C#의 날짜/시간

C#에서 DateTime의 더하기 및 빼기

DateTime 구조는 DateTime 개체에 날짜와 시간을 더하고 빼는 메서드를 제공합니다. DateTime 구조의 날짜를 DateTime 객체에 더하거나 뺄 수 있습니다. DateTime의 더하기 및 빼기에는 TimeSpan 구조를 사용합니다.

더하기 및 빼기의 경우 DateTime 개체의 Add 및 Subtract 메서드를 사용할 수 있습니다. 먼저 Add 및 Subtract 메서드를 사용하는 날짜 및 시간 값으로 TimeSpan을 만듭니다.

여기서는 오늘부터 30일을 더하고 빼서 콘솔에 날짜를 표시하는 코드를 생성합니다.

 using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime Day = DateTime.Now; TimeSpan Month = new System.TimeSpan(30, 0, 0, 0); DateTime aDayAfterAMonth = Day.Add(Month); DateTime aDayBeforeAMonth = Day.Subtract(Month); Console.WriteLine('{0:dddd}', aDayAfterAMonth); Console.WriteLine('{0:dddd}', aDayBeforeAMonth); } } } 

DateTime 구조에는 연도, 일, 시간, 분, 초를 추가하는 방법이 포함되어 있습니다.

DateTime 개체에 다른 구성 요소를 추가하려면 Add 메서드가 사용됩니다. .

 // To Add the Years and Days day.AddYears(2); day.AddDays(12); // Add Hours, Minutes, Seconds, Milliseconds, and Ticks Day.AddHours(4.25); day.AddMinutes(15); day.AddSeconds(45); day.AddMilliseconds(200); day.AddTicks(5000); 

DateTime에는 빼기 메서드가 포함되어 있지 않습니다. DateTime의 구성요소를 빼기 위해 빼기 메소드만 사용합니다. 예를 들어 DateTime에서 12일을 빼야 하는 경우 12일을 포함하는 DateTime 또는 TimeSpan 개체의 다른 개체를 만들 수 있습니다. 이제 DateTime에서 이 개체를 뺍니다. 대안으로 빼기 연산자를 사용하여 DateTime에서 DateTime 또는 TimeSpan을 뺄 수도 있습니다.

이제 DateTime의 개체를 생성하고 TimeSpan의 다른 DateTime 및 개체를 뺄 수 있는 코드를 생성하겠습니다. 코드에서는 DateTime에서 시간, 일 또는 기타 구성요소만 빼는 것을 보여줍니다.

 DateTime DOB = new DateTime(2000, 10, 20, 12, 15, 45); DateTime SubtractDate = new DateTime(2000, 2, 6, 13, 5, 15); // Use the TimeSpan with 10 days, 2 hrs, 30 mins, 45 seconds, and 100 milliseconds TimeSpan ts = new TimeSpan(10, 2, 30, 45, 100); // Subtract the DateTime TimeSpan Different = DOB.Subtract(SubtractDate); Console.WriteLine(Different.ToString()); // Subtract the TimeSpan DateTime Different2 = DOB.Subtract(ts); Console.WriteLine(Different2.ToString()); // Subtract 10 Days by creating the object SubtractedDays DateTime SubtractedDays = new DateTime(DOB.Year, DOB.Month, DOB.Day - 10); Console.WriteLine(SubtractedDays.ToString()); // Subtract hours, minutes, and seconds with creating the object HoursMinutesSeconds DateTime HoursMinutesSeconds = new DateTime(DOB.Year, DOB.Month, DOB.Day, DOB.Hour - 1, DOB.Minute - 15, DOB.Second - 15); Console.WriteLine(HoursMinutesSeconds.ToString()); 

해당 월의 날짜 검색

해당 월의 일수를 찾기 위해 정적 변수를 사용했습니다. 월간 일수 방법. 이 검색 방법 []은 1부터 12까지의 숫자로 매개변수를 사용합니다.

여기서는 특정 달의 일수를 알아내는 코드를 작성하겠습니다.

여기서는 2020년 2월의 일수를 알아 보겠습니다. 출력은 28일입니다.

 int NumberOfDays = DateTime.DaysInMonth(2004, 2); Console.WriteLine(NumberOfDays); 

동일한 기술을 사용하여 1년의 총 일수를 알아낼 수 있습니다. 이를 위해 DaysInYear 메서드를 사용합니다.

 private int DaysInYear(int year) { int DaysIN= 0; for (int j = 1; j <= 12; j++) { daysin +="DateTime.DaysInMonth(year," j); } return daysin; < pre> <h2>Comparison of two DateTime in C#</h2> <p> <strong>The comparer</strong> static method is used to compare the object of the two datetime. If the objects of both <strong>DateTime</strong> is the same, then the result will be 0. If the first DateTime is earlier, then the result will be 0 else the first DateTime would be later.</p> <p> <strong>Now we will show the comparison of the two datetime objects in C#.</strong> </p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateOfFirst = new DateTime(2002, 10, 22); DateTime DateOfSecond = new DateTime(2009, 8, 11); int result1 = DateTime.Compare(DateOfFirst, DateOfSecond); if (result1 <0) console.writeline('date of first is earlier'); else if (result1="=" 0) console.writeline('both dates are same'); later'); } < pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-2.webp" alt="DateTime in C#"> <h2>CompareTo Method</h2> <p>CompareTo method is used to compare the two dates. We will assign the DateTime or object in this method.</p> <p>To compare the two DateTime object, we used the CompareTo method. Below we have a C# code to compare the DateTime object.</p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateOfFirst = new DateTime(2001, 10, 20); DateTime DateOfSecond = new DateTime(2009, 8, 11); int ResultOfComparison = DateOfFirst.CompareTo(DateOfSecond); if (ResultOfComparison <0) console.writeline('date of first is earlier'); else if (resultofcomparison="=" 0) both are same'); later'); } < pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-3.webp" alt="DateTime in C#"> <h2>Formatting of the DateTime in C#</h2> <p>In C#, we can format the DateTime to any type of string format as we want.</p> <p>For the formatting of the DateTime, we used the <strong>GetDateTimeFormats</strong> method, which returns all the possible DateTime formats for the current culture of the computer.</p> <p>Here we have a C# code that returns the array of the strings of all the possible standard formats.</p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateOfMonth = new DateTime(2020, 02, 25); string[] FormatsOfDate = DateOfMonth.GetDateTimeFormats(); foreach (string format in FormatsOfDate) Console.WriteLine(format); } } } </pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-4.webp" alt="DateTime in C#"> <br> <img src="//techcodeview.com/img/net-framework/10/datetime-c-5.webp" alt="DateTime in C#"> <p>We can overload the <strong>GetDateTimeFormats</strong> method, which takes the format specifier as a parameter and converts the DateTime to that format. To get the desired format, we need to understand the format of the <strong>DateTime</strong> specifiers.</p> <p>We will show it with the code with the pattern in a table.</p> <table class="table"> <tr> <th>Code</th> <th>Pattern</th> </tr> <tr> <td>&apos;d&apos;</td> <td>Short date</td> </tr> <tr> <td>&apos;D&apos;</td> <td>Long date</td> </tr> <tr> <td>&apos;f&apos;</td> <td>Full date time. Short time.</td> </tr> <tr> <td>&apos;F&apos;</td> <td>Full date time. Long Time.</td> </tr> <tr> <td>&apos;g&apos;</td> <td>Generate date time. Long Time.</td> </tr> <tr> <td>&apos;G&apos;</td> <td>General date time. Long Time.</td> </tr> <tr> <td>&apos;M&apos;,&apos;m.&apos;</td> <td>Month/day</td> </tr> <tr> <td>&apos;O&apos;,&apos;o&apos;</td> <td>Round trip date/time.</td> </tr> <tr> <td>&apos;R&apos;,&apos;r&apos;</td> <td>RFC1123</td> </tr> <tr> <td>&apos;s&apos;</td> <td>Sortable date time.</td> </tr> <tr> <td>&apos;t&apos;</td> <td>Sort Time</td> </tr> <tr> <td>&apos;T&apos;</td> <td>Long Time</td> </tr> <tr> <td>&apos;u&apos;</td> <td>Universal sortable date time.</td> </tr> <tr> <td>&apos;U&apos;</td> <td>Universal full date-time.</td> </tr> <tr> <td>&apos;Y&apos;,&apos;y&apos;</td> <td>Year, Month</td> </tr> </table> <p> <strong>We will specify the format of the DateTime in the below C# Code. </strong> </p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime FormatOfDate = new DateTime(2020, 02, 25); // DateTime Formats: d, D, f, F, g, G, m, o, r, s, t, T, u, U, Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;d Formats&apos;); Console.WriteLine(&apos;----------------&apos;); string[] DateFormat = FormatOfDate.GetDateTimeFormats(&apos;d&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;D Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;D&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;f Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;f&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;F Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;F&apos;); foreach (string format in DateFormat) Console.WriteLine(format); } } } </pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-6.webp" alt="DateTime in C#"> <br> <img src="//techcodeview.com/img/net-framework/10/datetime-c-7.webp" alt="DateTime in C#"> <p>We can also do the formatting of the DateTime by passing the format specifier in the ToString() method of DateTime. Now we will write the C# code for the formatting of the DateTime using the ToString() method.</p> <pre> Console.WriteLine(DateOfFormat.ToString(&apos;r&apos;)); </pre> <p>Now we will write a C# code for the DateTime format specifiers within the ToString() method.</p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-8.webp" alt="DateTime in C#"> <h2>Get the Leap Year and Daylight-Saving Time</h2> <p>Through the C# Code, we will get the Leap Year and Daylight-Saving Time.</p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateOfTime = new DateTime(2020, 02, 22); Console.WriteLine(DateOfTime.IsDaylightSavingTime()); Console.WriteLine(DateTime.IsLeapYear(DateOfTime.Year)); } } } </pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-9.webp" alt="DateTime in C#"> <h2>Conversion of string to the DateTime</h2> <p>To convert the string to a DateTime object, we used the Parse method. In the Parse method, the passing string must have the correct format of the DateTime. For the conversion of the DateTime to the String, the ToString() method is used. </p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { string DT = &apos;2020-02-04T20:12:45-5:00&apos;; DateTime NEWDt = DateTime.Parse(DT); Console.WriteLine(NEWDt.ToString()); } } } </pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-10.webp" alt="DateTime in C#"> <h2>Conversion of DateTime in C#</h2> <p>The structure of the DateTime is full of self-explanatory conversion, which converts the DateTime to the specific type. The methods are ToFileTime, ToLocalTime, ToLongDateString, ToBinary ,ToLongTimeString, ToOADate, ToShortDateString, ToShortTimeString, ToString, and ToUniversalTime.</p> <p>Here we will take an example of C# to convert the DateTime to the specific type.</p> <pre> using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DOB = new DateTime(2020, 01, 22); Console.WriteLine(&apos;ToString: &apos; + DOB.ToString()); Console.WriteLine(&apos;ToBinary: &apos; + DOB.ToBinary()); Console.WriteLine(&apos;ToFileTime: &apos; + DOB.ToFileTime()); Console.WriteLine(&apos;ToLocalTime: &apos; + DOB.ToLocalTime()); Console.WriteLine(&apos;ToLongDateString: &apos; + DOB.ToLongDateString()); Console.WriteLine(&apos;ToLongTimeString: &apos; + DOB.ToLongTimeString()); Console.WriteLine(&apos;ToOADate: &apos; + DOB.ToOADate()); Console.WriteLine(&apos;ToShortDateString: &apos; + DOB.ToShortDateString()); Console.WriteLine(&apos;ToShortTimeString: &apos; + DOB.ToShortTimeString()); Console.WriteLine(&apos;ToUniversalTime: &apos; + DOB.ToUniversalTime()); } } } </pre> <p> <strong>Output:</strong> </p> <img src="//techcodeview.com/img/net-framework/10/datetime-c-11.webp" alt="DateTime in C#"> <hr></0)></pre></0)></pre></=>

산출:

C#의 날짜/시간
C#의 날짜/시간

우리는 GetDateTime형식 형식 지정자를 매개 변수로 사용하고 DateTime을 해당 형식으로 변환하는 메서드입니다. 원하는 형식을 얻으려면 형식을 이해해야 합니다. 날짜 시간 지정자.

패턴을 포함한 코드를 표로 보여드리겠습니다.

암호 무늬
'디' 짧은 데이트
'디' 긴 데이트
'에프' 전체 날짜 시간. 짧은 시간.
'에프' 전체 날짜 시간. 장기.
'g' 날짜 시간을 생성합니다. 장기.
'G' 일반 데이트 시간. 장기.
'Mm.' 월 일
'오','오' 왕복 날짜/시간.
'R','r' RFC1123
'에스' 정렬 가능한 날짜 시간.
'티' 정렬 시간
'티' 장기
'안에' 범용 정렬 가능한 날짜 시간.
'안에' 범용 전체 날짜 시간.
'그리고','그리고' 년, 월

아래 C# 코드에서 DateTime의 형식을 지정합니다.

 using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime FormatOfDate = new DateTime(2020, 02, 25); // DateTime Formats: d, D, f, F, g, G, m, o, r, s, t, T, u, U, Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;d Formats&apos;); Console.WriteLine(&apos;----------------&apos;); string[] DateFormat = FormatOfDate.GetDateTimeFormats(&apos;d&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;D Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;D&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;f Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;f&apos;); foreach (string format in DateFormat) Console.WriteLine(format); Console.WriteLine(&apos;----------------&apos;); Console.WriteLine(&apos;F Formats&apos;); Console.WriteLine(&apos;----------------&apos;); DateFormat = FormatOfDate.GetDateTimeFormats(&apos;F&apos;); foreach (string format in DateFormat) Console.WriteLine(format); } } } 

산출:

java와 정수 비교
C#의 날짜/시간
C#의 날짜/시간

DateTime의 ToString() 메서드에 형식 지정자를 전달하여 DateTime의 형식을 지정할 수도 있습니다. 이제 ToString() 메서드를 사용하여 DateTime 형식을 지정하기 위한 C# 코드를 작성하겠습니다.

 Console.WriteLine(DateOfFormat.ToString(&apos;r&apos;)); 

이제 ToString() 메서드 내에서 DateTime 형식 지정자에 대한 C# 코드를 작성하겠습니다.

C#의 날짜/시간

윤년과 일광 절약 시간을 확인하세요

C# 코드를 통해 윤년과 일광 절약 시간을 얻습니다.

 using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DateOfTime = new DateTime(2020, 02, 22); Console.WriteLine(DateOfTime.IsDaylightSavingTime()); Console.WriteLine(DateTime.IsLeapYear(DateOfTime.Year)); } } } 

산출:

C#의 날짜/시간

문자열을 DateTime으로 변환

문자열을 DateTime 객체로 변환하기 위해 Parse 메서드를 사용했습니다. Parse 메서드에서 전달 문자열은 DateTime의 올바른 형식을 가져야 합니다. DateTime을 문자열로 변환하려면 ToString() 메서드가 사용됩니다.

 using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { string DT = &apos;2020-02-04T20:12:45-5:00&apos;; DateTime NEWDt = DateTime.Parse(DT); Console.WriteLine(NEWDt.ToString()); } } } 

산출:

C#의 날짜/시간

C#에서 DateTime 변환

DateTime의 구조는 DateTime을 특정 유형으로 변환하는 자체 설명적 변환으로 가득 차 있습니다. 메서드는 ToFileTime, ToLocalTime, ToLongDateString, ToBinary, ToLongTimeString, ToOADate, ToShortDateString, ToShortTimeString, ToString 및 ToUniversalTime입니다.

여기서는 DateTime을 특정 유형으로 변환하는 C#의 예를 살펴보겠습니다.

 using System; using System. Collections; using System.Collections.Generic; using System. Linq; using System. Text; using System.Threading.Tasks; namespace ConsoleApp8 { class Program { static void Main(string[] args) { DateTime DOB = new DateTime(2020, 01, 22); Console.WriteLine(&apos;ToString: &apos; + DOB.ToString()); Console.WriteLine(&apos;ToBinary: &apos; + DOB.ToBinary()); Console.WriteLine(&apos;ToFileTime: &apos; + DOB.ToFileTime()); Console.WriteLine(&apos;ToLocalTime: &apos; + DOB.ToLocalTime()); Console.WriteLine(&apos;ToLongDateString: &apos; + DOB.ToLongDateString()); Console.WriteLine(&apos;ToLongTimeString: &apos; + DOB.ToLongTimeString()); Console.WriteLine(&apos;ToOADate: &apos; + DOB.ToOADate()); Console.WriteLine(&apos;ToShortDateString: &apos; + DOB.ToShortDateString()); Console.WriteLine(&apos;ToShortTimeString: &apos; + DOB.ToShortTimeString()); Console.WriteLine(&apos;ToUniversalTime: &apos; + DOB.ToUniversalTime()); } } } 

산출:

C#의 날짜/시간