l         .NET 날짜와 시간 표시 부분만을 정리 것입니다.

 

Item

Description

Format

Year

4 digit Year with century (1998 or 2003)

yyyy

2 digit Year without century (98 or 03)

yy

1,3 digit Year (3 for 2003)

y

Era (BC/AD)

gg

Month

Month as a decimal (02)

MM

Month without leading zero (2)

M

Abbreviated month name (Feb)

MMM

Full month name (February)

MMMM

Week

Abbreviated day name (Fri)

ddd

Weekday Name (Friday)

dddd

Day

Day of the month (03)

dd

Day without leading zero (3)

d

Time

Hour in 24 hour format (24)

H,HH

Hour in 12 hour format (03)

h,hh

Minute of hour as an integer (01)

m,mm

Second in minute (55)

ss

Second in minute with no leading zero (5)

s

 

l         아래는 Format 문자열을 이용한 예제 코드입니다.

 

using System;

 

class Program

{

  static void Main(string[] args)

  {

      Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd"));

      Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:ss"));

      Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd hh:ss.fff"));

      Console.WriteLine(DateTime.Now.ToString("(tt) yyyy-MM-dd hh:ss.fff"));

      Console.WriteLine(DateTime.Now.ToString("(tt) yyyy-MM-dd hh:ss.fffzz"));

}

}

 

l         아래는 예제 코드를 실행 결과입니다.

 2006-03-21

2006-03-21 11:35

2006-03-21 11:35.206

(오전) 2006-03-21 11:35.206

(오전) 2006-03-21 11:35.206+09

Posted by 뭉치냐옹
: