프로그래밍/.NET2013. 5. 8. 22:21

 class Program

{
    static void Main(string[] args)
    {
        string strDate;
        DateTime dtDate;

        // Convert.ToDateTime
        strDate = "13-05-01";
        strDate = "2013-05-01";
        //strDate = "20130501";       // error
        dtDate = Convert.ToDateTime(strDate);   

        // DateTime.Paser
        strDate = "13-05-01";
        strDate = "2013-05-01";
        //strDate = "20130501";       // error
        dtDate = DateTime.Parse(strDate);

        // DateTime.PaserExact
        strDate = "20130501";
        dtDate = DateTime.ParseExact(strDate, "yyyyMMdd", null);
    }
}


Posted by 건깡