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


Top 5 Contributors of the Month
david stephan

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)
{
            try
            {
                CultureAndRegionInfoBuilder.Unregister("en-US");
            }
            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";  
            CulRegInfoBuilder.Register();  
            
            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;  
                    web.Update();  
                }  
            }

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


     

Further Readings:

Responses

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