MVC3 Cultures vs jQuery UI Date Formats - asp.net-mvc-3

I am having a problem with an MVC3 application using a jQuery UI DatePicker object.
Within the MVC application, I ask the user to pick their required culture, i.e en-GB, which then formats all dates and currencies in the application in the british format.
I can then access the formatter code for this via Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern
However, the format returned for UK dates is: dd/MM/yyyy
To format the resulting data from the jQuery UI datepicker, I need to specify a date format. But for UK format dates, I need to specify the format as dd/mm/yy
The simple solution would be to just use Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern in my jQuery calls to format the date, but obviously this gives a formatting inconsistency as this is interpreted differently by jQuery UI (01/December/20112011 instead of 01/12/2011)
Is there any easy way around this?
The only way I can think of doing it is asking the user twice what format to display dates in?

I could think of another solution, but that's pretty low-tech, I'm not sure if that is the right way to do it:
var dateTime = Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;
var lowerCaseMonths = Regex.Replace(dateTime, "MM","mm");
var yearOnlyOnce = Regex.Replace(lowerCaseMonths, "yyyy", "yy");
Without "explaining variables" just
Regex.Replace(Regex.Replace(Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern, "MM","mm"), "yyyy", "yy")
Then I guess no matter in what format it is, dd/MM/yyyy MM/DD/yyyy dd-MM-yyyy etc, it should work out in jQuery.
Maybe someone has a better solution, but at least this seems better than asking for user input twice.

#System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern.ToLower().Replace("yyyy", "yy")

Related

How to make consistent url format for news item across translations in Sitefinity?

My application have Arabic and English languages enabled. When the url is generated for news items, the date component is present in the URL and its different for each language. Gregorian date for English translation and Hijri date components for arabic item's url.
The requirement here is to have same date (Gregorian) in both items url, is there any fix or options available to change this?
Thanks
Salam
That's not gonna be easy, because when the Thread is in AR culture, then calling date.ToString("yyyy/MM/dd") returns something completely different compared to when the Thread is in EN culture, as you correctly pointed out.
What Sitefinity allows you to do, is to change the urlformat of the news items, so the easiest way would be to remove the PublicationDate from the url format altogether. As a result the news url will not have a date portion.
If that's acceptable for you, then check how to do it here:
https://www.progress.com/documentation/sitefinity-cms/for-developers-change-url-format-for-built-in-modules-with-single-content-type
Simply create this urlFormat parameter and set its value to
/[UrlName]

PDF date field - one format, multiple valid inputs

I need to create a PDF with a date field that displays dates in the format dd.mm.yyyy. This field must be validated and should also accept inputs in other formats.
For example, users should be able to input dates in the form dd.mm.yy, which will then be expanded to dd.mm.20yy (MS Office apps like Excel do this).
Alternatively, selecting multiple valid formats would be an acceptable solution.
What currently happens:
If the date format of the field is set to dd.mm.yyyy, dd.mm.yy is rejected.
If the date format of the field is set to dd.mm.yy, dd.mm.yyyy is accepted (but formatted to dd.mm.yy).
The last behaviour is almost what i need, just with the wrong format.
Is there a way to do this without custom Javascript? If not, is there a way to still use the built-in formatting or do i have to rewrite everything in JS?
Unfortunately this is not achievable with Acrobat's built-in formatting.
One thing to add to your second bullet point: it trims the date down to .yy when you exit the field, but it still retains all four digits. When you click into the field, it will revert back to being .yyyy. That may or may not matter depending on how you're using it.
Regarding a custom validation, a quick Google search will yield an abundance of Javascript date validation scripts. Something like this could probably be quickly repurposed for your application.

VB datetimepicker format as 09-SEP-2012

I am trying to get datetimepicker to return the date in the following format: 08-SEP-2012.
The returned format will be part of a web address and therefore very specific.
It is set on custom formatting, and I can get the day and year right. only the 3 letter month give me a problem. Maybe there is a very simple solution but I can't find it..
I'm fairly new to Visual Basic (or any programming in general) so any assistance would be greatly appreciated.
To convert a date into a string in your required format, use:
Dim s = theDate.ToString("dd-MMM-yyyy").ToUpper()

Ask for some advices for WebPart internationalization

Recently,I am handling a solution for WebPart internationalization,but I am not familiar with the culture or habits in different regions.So I am asking for some information if you are glad to help.
Suppose I am a different person in another region,for example,a German.I am using the SharePoint,which is a German edition.So,
1) What's the input habit of me?
For example,if I need to input "10000",will I input "10.000,00" or just "10000"?Which is frequent to the user?
2) How to handle the "Date" and "Time" format?
I think it's better if I can select the date or time instead of inputing the date or time string.
3) Any information that you think will be helpful to me?
That is very kind of you,thanks for your help!
To be honest, I am not sure how you want to handle i18n, but I am assuming that you want to do this on the client side.
In this case, I can recommend using Globalize for formatting (both numerical values and date/time could be handled this way).
As for parsing dates (that is handling dates provided by user), there is actually even easier way - just use jQuery UI Datepicker with valid regional script. Obtaining Date object is as easy as calling Datepicker's getDate method.

Does jqGrid's datefmt support JavaScript date formats?

Does jqGrid's datefmt support the JavaScript date syntax or only the PHP date syntax? The jqGrid documentation doesn't seem to be clear about the excepted formats.
The best place to answer on such question is to look in the source code of the date formatter. How you can see from the place in the code jqGrid supports only one character formatting syntax from PHP. I personally don't use PHP and would prefer another date format. Moreover having another date format one can easy use globalization plugin.
You can try to place new feature request in the trirand forum. If would be nice to be able to choose format of date as additional jqGrid parameter.

Resources