LightSwitch Howtos: Change the Date Format
In this short blog, you will learn how to change the Date format in your Microsoft® Visual Studio® LightSwitch™ 2011 application.
By default, the Date format is controlled by the locale in your Control Panel. This will insure that the correct date format will be displayed to your user. Therefore you don’t have to worry about it.
As usual, you need to tweak and control our display. There are a couple of interesting means to adjust the date format.
First, you can set the display to the long date format. This is accomplished by checking a checkbox in your display of while creating your date object. Check the below screenshot:
Second, if you need more control over the date format. You can add a computed field, possibly a string, and on the calculate string, define your specific format. Follow these steps:
1) Create a computed property called “CreateDateDisplay”
2) Handle the “Compute” method.
3) Add your code, in the below example, I added code to use the US date formatting.
partial void CreateDateDisplay_Compute(ref string result)
cInfo = new System.Globalization.CultureInfo("en-US");
result = CreateDate.Date.ToString("d",cInfo);
I hope you liked this post and check soon for more posts.