Geeks With Blogs
Welcome to
Geeks with Blogs
Login
Michael Freidgeim
Personal Website / Bio
587 Posts
| 965 Comments
My Other Recent Posts
Batch file that required administrative privileges.
PowerShell function to delete if exist and create empty folder
Pocket on IPad: Ability to rename articles is still missing
Read CSV files with multiple lines
Tiny MCE editor in ASP.Net Web Form
Methods to verify, are DataTables or DataSets the same.
2 options to write tests for WCF Services
Angular JS vs Knockout JS -quotes and links
POSTSHARP error PS0052: The plug-in "PostSharp.Patterns.Diagnostics.Weaver" was not found
Misleading compiler error "is a 'type' but is used like a 'variable'"
News
My Blog has been MOVED to
https://mfreidge.wordpress.com
Post Categories
Ravings of a Lunatic
Now I've heard everything
Valuable Reading
Technical
Free SWAG Babies
Travel Information
Humour
Bummers
General
That's Cool!
Office 2007
WPF
MVVM
VSTS 2008
VSTS 2008 DB Edition
Windows Phone 8
Writing
Archives
April 2016 (1)
February 2016 (9)
January 2016 (5)
August 2013 (6)
July 2013 (1)
June 2013 (5)
May 2013 (3)
March 2013 (3)
February 2013 (5)
December 2012 (4)
November 2012 (1)
October 2012 (4)
September 2012 (4)
August 2012 (3)
July 2012 (3)
June 2012 (4)
May 2012 (3)
April 2012 (11)
March 2012 (4)
January 2012 (3)
December 2011 (2)
November 2011 (1)
October 2011 (1)
September 2011 (8)
August 2011 (1)
July 2011 (4)
June 2011 (16)
May 2011 (11)
July 2010 (4)
June 2010 (8)
May 2010 (3)
March 2010 (1)
December 2009 (1)
November 2009 (3)
September 2009 (3)
August 2009 (1)
July 2009 (5)
June 2009 (5)
May 2009 (7)
April 2009 (2)
March 2009 (5)
February 2009 (5)
January 2009 (10)
December 2008 (8)
November 2008 (7)
October 2008 (5)
September 2008 (3)
August 2008 (4)
July 2008 (15)
June 2008 (4)
May 2008 (12)
April 2008 (6)
March 2008 (6)
February 2008 (14)
January 2008 (11)
December 2007 (2)
November 2007 (3)
October 2007 (18)
September 2007 (7)
August 2007 (2)
July 2007 (6)
June 2007 (9)
May 2007 (10)
April 2007 (2)
March 2007 (19)
February 2007 (5)
January 2007 (3)
December 2006 (6)
November 2006 (6)
October 2006 (7)
September 2006 (10)
August 2006 (17)
July 2006 (9)
June 2006 (6)
May 2006 (9)
April 2006 (7)
March 2006 (21)
February 2006 (22)
January 2006 (11)
December 2005 (5)
November 2005 (5)
October 2005 (8)
September 2005 (5)
August 2005 (4)
July 2005 (2)
Michael Freidgeim's OLD Blog
My Blog has been MOVED to
https://mfreidge.wordpress.com
<< Copy to local drive before running installations
|
Home
|
Visual Studio 10 crashed when tried to open one of solutions >>
Translate jQuery UI Datepicker format to .Net Date format
Comments
|
Share
I needed to use the same date format in client jQuery UI Datepicker and server ASP.NET code. The actual format can be different for different localization cultures.
I decided to translate
Datepicker format
to
.Net Date format
similar as it was asked to do opposite operation in
http://stackoverflow.com/questions/8531247/jquery-datepickers-dateformat-how-to-integrate-with-net-current-culture-date
Note that replace command need to replace whole words and order of calls is important
Function that does opposite operation (translate
.Net Date format
to
Datepicker format
) is described in
http://www.codeproject.com/Articles/62031/JQueryUI-Datepicker-in-ASP-NET-MVC
/// <summary>
/// Uses regex '\b' as suggested in //http://stackoverflow.com/questions/6143642/way-to-have-string-replace-only-hit-whole-words
/// </summary>
/// <param name="original"></param>
/// <param name="wordToFind"></param>
/// <param name="replacement"></param>
/// <param name="regexOptions"></param>
/// <returns></returns>
static public string ReplaceWholeWord(this string original, string wordToFind, string replacement,
RegexOptions
regexOptions =
RegexOptions
.None)
{
string
pattern =
String
.Format(
@"\b
{0}
\b"
, wordToFind);
string ret=
Regex
.Replace(original, pattern, replacement, r
egexOptions
);
return ret;
}
/// <summary>
/// E.g "DD, d MM, yy" to ,"dddd, d MMMM, yyyy"
/// </summary>
/// <param name="datePickerFormat"></param>
/// <returns></returns>
/// <remarks>
/// Idea to replace from http://stackoverflow.com/questions/8531247/jquery-datepickers-dateformat-how-to-integrate-with-net-current-culture-date
///From http://docs.jquery.com/UI/Datepicker/$.datepicker.formatDate to http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
///Format a date into a string value with a specified format.
///d - day of month (no leading zero)
---.Net the same
///dd - day of month (two digit)
---.Net the same
///D - day name short
---.Net "ddd"
///DD - day name long
---.Net "dddd"
///m - month of year (no leading zero)
---.Net "M"
///mm - month of year (two digit)
---.Net "MM"
///M - month name short
---.Net "MMM"
///MM - month name long
---.Net "MMMM"
///y - year (two digit)
---.Net "yy"
///yy - year (four digit)
---.Net "yyyy"
/// </remarks>
public static string JQueryDatePickerFormatToDotNetDateFormat(string datePickerFormat)
{
string sRet = datePickerFormat.ReplaceWholeWord(
"DD"
,
"dddd"
).ReplaceWholeWord(
"D"
,
"ddd"
);
sRet = sRet.ReplaceWholeWord(
"M"
,
"MMM"
).ReplaceWholeWord(
"MM"
,
"MMMM"
).ReplaceWholeWord(
"m"
,
"M"
).ReplaceWholeWord(
"mm"
,
"MM"
);//order is important
sRet = sRet.ReplaceWholeWord(
"yy"
,
"yyyy"
).ReplaceWholeWord(
"y"
,
"yy"
);//order is important
return sRet;
}
Posted on Saturday, April 14, 2012 10:40 AM
ASP.NET
,
CSS/DHTML/JavaScript
|
Back to top
Related Posts on Geeks With Blogs
Matching Categories
Creating Trimmed Self Contained Executables in .NE...
asp.net
Unit Testing With .NET Core
asp.net
Benefits of customized .NET Application Developmen...
asp.net
Relating Umbraco Content With the Content Picker
ASP.NET
Umbraco Team Development
ASP.NET
Comments on this post: Translate jQuery UI Datepicker format to .Net Date format
No comments posted yet.
Your comment:
Title:
Name:
Email: (never displayed)
(will show your
gravatar
)
Comment:
Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
Verification:
Copyright © Michael Freidgeim | Powered by:
GeeksWithBlogs.net
Popular Posts on Geeks with Blogs
0
Code Monkey Projectiles - Index
How to use CLI to create dotnet project from powershell or CMD
Full Stack Engineering Publication
5 Benefits of Agile Project Management
angular proxy cli to help with CORS
Geeks With Blogs Content Categories
ASP.Net
SQL Server
Apple
Google
SharePoint
Windows
Visual Studio
Team Foundation Server
Agile
Office
Design Patterns
Web
Azure
Brand New Posts on Geeks with Blogs
0
Build and Deploy a Blazor App Without Touching a Windows Machine
angular proxy cli to help with CORS
How to use CLI to create dotnet project from powershell or CMD
5 Benefits of Agile Project Management
Full Stack Engineering Publication