C # create yyyy-mm-dd dir easy

How do I do to create the yyyy / mm / dd directory? mysite.com/blog ** / 2009/01/01 / ** hi-world.aspx!

0


a source to share


3 answers


String.Format(CultureInfo.InvariantCulture, 
              "mysite.com/blog**/{0:yyyy/MM/dd}/**hello-world.aspx", 
              DateTime.Now)

      



You will receive the date. You can add a few more parameters to it to get the best results possible.

+9


a source


Use the Uri class to concatenate the urls together and use / to escape the \ character to be an explicit rather than a cultural date separator.



Uri oSiteBase = new Uri("http://mysite.com/blog");
Uri oSiteDay = new Uri(oSiteBase, DateTime.Now.ToString("yyyy\/MM\/dd"));

      

0


a source


Jeff's answer:

String foo = "mysite.com/blog/" + DateTime.Now.ToString("yyyy\/mm\/dd") + "/hello-world.aspx";

      

0


a source







All Articles