Parse and format date in c#

when use '/' in pattern, must use '\' to escape it,
when get formatted date string, use the following method:

datefrom.ToString("yyyy-MM-dd")

   1: DateTime datefrom;
   2: try
   3: {
   4:     datefrom = DateTime.ParseExact(txtFromDate.Text.Trim(), "MM\\/dd, yyyy", null); 
   5: }
   6: catch (Exception)
   7: {
   8:     datefrom = new DateTime(1900, 1, 1); 
   9: }
 

posted on 2007-08-17 15:18  Wade  阅读(631)  评论(0编辑  收藏  举报

导航