.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Change Date Format in SharePoint

Posted By:volvo       Posted Date: December 19, 2013    Points: 25    Category: SharePoint    URL: http://www.dotnetspark.com  

Below code block explains that how to change date format from MM/DD/yyyy to yyyy/DD/MM without altering the locale of Site.

using Microsoft.SharePoint;
using System.Globalization;
static void Main(string[] args)
            catch { }

            CultureAndRegionInfoBuilder CulRegInfoBuilder = new CultureAndRegionInfoBuilder("en-US", CultureAndRegionModifiers.Replacement);
            CulRegInfoBuilder.LoadDataFromCultureInfo(new CultureInfo("en-US"));  
            CulRegInfoBuilder.LoadDataFromRegionInfo(new RegionInfo("en-US"));  
            CulRegInfoBuilder.GregorianDateTimeFormat.ShortDatePattern = "yyyy/MM/dd";  
            CultureInfo ci = new CultureInfo("en-US");

            string siteUrl = string.Empty;
            Console.WriteLine("Enter your site url");
            siteUrl = Console.ReadLine();

            using(SPSite site = new SPSite(siteUrl))  
                using(SPWeb web = site.RootWeb)  
                    web.Locale = ci;  

            Console.WriteLine("Date format changed succesfully.");


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend