user105496
user105496

Reputation:

C# create yyyy-mm-dd dir easy

How should i do to create yyyy/mm/dd directory easy?
mysite.com/blog**/2009/01/01/**hello-world.aspx!

Upvotes: 0

Views: 2895

Answers (3)

Brian
Brian

Reputation: 25844

A variation on Jeff's answer:

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

Upvotes: 0

stevehipwell
stevehipwell

Reputation: 57568

Use the Uri class to combine the url together and use / to escape the \ character to be explicit rather than the cultural date seperator.

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

Upvotes: 0

Jeff Moser
Jeff Moser

Reputation: 20053

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

Will get you the date. You can add more parameters to it to get it just right.

Upvotes: 9

Related Questions