Where can I browse RFC and ISO datetime formats? - datetime

I'm looking to write a function to convert my server-side datetimes into my user interface datetimes, and I haven't decided on a format for either. Ideally, I'd like my function to take one standard datetime format, and return another standard datetime format.
Is there a cheat sheet, web site, or a spreadsheet that visually shows the difference between many standard date formats side by side? I'm looking for something like the "localized notations" documentation for PHP's compound date and time formats, only more comprehensive.
Are there any standards that are designed for presentation to end users - something like "January 4th, 1983 6:34 PM"?

Use and store dates in a simple, unambigous format like ISO-8601.
Rely on operating system support to convert these ISO dates into a nice localized display format. Otherwise you are just duplicating (*) the OS.
(*) : and probably "duplicating badly" because MS and Apple have far more experience and resources than you.

Have you looked at the Wikipedia article on ISO-8601? I usually try to use one of those formats when outputting dates. Additionally, the link in that article to RFC 3339 has some examples. I'm not sure if these fit your side-by-side desire, but they're a start. You might find Wikipedia's Date and time notation by country useful in that regard.

Related

How to get DateTime.TryParse to parse dates in the "ddMMyyyy" format?

I need to parse dates that might be in the format "ddMMyyyy" as well as in the standard GB English formats (e.g. "dd/mm/yyyy"), and I'm trying to use the DateTime.TryParse() method to do it but it doesn't recognise the "ddMMyyyy" format.
I know I can use Date.TryParseExact() and specify the custom format each time, but that means doing two checks for each date (one for the custom format and one for the culture's standard formats) and it just seems that there must be a better way.
Is there a way to get the DateTime.TryParse() method to recognise custom date formats as well as the standard formats?
I don't think that it's possible to set DateTime.TryParse() to recognize any of two date formats at the same time. Looking at the overrides for DateTime.TryParse() you have .TryParse(String, DateTime) and TryParse(String, IFormatProvider, DateTimeStyles, DateTime), therefore the maximum of flexibility here lets you provide a IFormatProvider that could be a DateTimeFormatInfo class, but DateTimeFormatInfo can only deal with one set of formats at a time.
One shot (I did not try it) would be to create a new DateTimeFormatInfo class with different LongDatePattern and ShortDatePattern patterns (matching the ones you want to use), and pass the instance as a parameter to TryParse, but checking two times with Date.TryParseExact() seems way more reasonable.
Howw about using DateTime.TryParseExact
MSDN link
I'm afraid that date parsers tend not to be too intelligent, mostly by design. While you may want to parse a "ddMMyyyy" date, someone else may want to parse a "yyyyMMdd" date. In some circumstances, these may be identical (what is "20121220"?). The parser is dumb, and you must tell it which format to use. If you specify multiple formats, then it'd need to try them one at a time, which is exactly what you are trying to avoid.
If you really only want to take a single pass, you could use a regex to extract the pertinent parts ("(?<Day>\d{2})/?(?<Month>\d{2})/?(?<Year>\d{4})") then reconstitute it into a format recognized by the parser (string.Format("{0}/{1}/{2}", match.Groups["Day"].Value, match.Groups["Month"].Value, match.Groups["Year"].Value)).
Honestly, though, it'd probably be more efficient to just use String.Contains("/") in an if statement.

Chrome Flash Player (Pepper) date timezoneOffset bug

I had a hard time finding anything on this critical problem so I decide to post this to help users running into the same issue.
The Chrome embedded Flash Player (Pepper) has a bug concerning date timezoneOffset that leads to some unpredictable behaviors when your application deals with dates.
As we provide a commercial Flex calendar component (KC-Calendar), this issue is critical for our clients and for their applications.
The issue details can be found here: http://code.google.com/p/chromium/issues/detail?id=154060
(please vote)
Waiting for a fix, if someone has a workaround, it could be really helpful.
Thanks in advance!
We've dealt with such issues before, and honestly--rather than playing around with trying to serialize Dates--IMO the best solution (unless you WANT auto timezone conversion) is to simply pass date data types as strings. We do this cleanly using Java and ActionScript getters/setters which (correctly) set the serialized "date" objects in our DTO by parsing the un-adjusted date strings.
Ex. when you set a Date object's value, in the setter you convert Date to String & set a String field for that date. In the getter you get the String value for that date and parse it, returning a new Date object. Do this on server and client side.
The only minor caveat, obviously, is that you need to ensure the Flex & server side String-to-Date/Date-To-String functions use the same date format. Just put a nice comment explaining this (so nobody screws with it) next to your serialization date parsers/formatters and you're fine.
I expect this issue will probably go away once an HTML5-based Flex compiler is released (it's really just a Flash feature which isn't the desired behavior in our cases).

mvc3 format phone number

I want to display the phone number like this (999) 999-9999 I thought the css class would do this but it doesn't
<td>#Html.Encode(Model.PhoneModel.PhoneNumber)</td>.
I tried this, but it doesn't work
#String.Format("{0:(###) ###-####}",Model.PhoneModel.PhoneNumber.ToString())
I got this to work, but I don't like the fact that it's regrex.
#Regex.Replace(Model.PhoneModel.PhoneNumber, #"(\d{3})(\d{3})(\d{4})", "($1) $2-$3")
You may want to look at changing how you are outputting the values. Consider this article from Phil Haack.
http://haacked.com/archive/2010/04/28/replacing-html-encode.aspx
EDIT:
To address your edit of formatting as a phone number reference this thread:
How to format a string as a telephone number in C#
String.Format("{0:(###) ###-####}", 8005551212);
There's not much point in spending too much effort on formatting phone numbers, when others have done all the work for you. Check out http://code.google.com/p/libphonenumber/ for a library which will format numbers (and convert them back to a standard format) for you. It's also available on nuget as libphonenumber-csharp.

asp.net Web forms internationalization

I'm still pretty new to asp.net web forms. I have a requirement to make app available in two languages. Everything that has to be translated is static content. Can you point me to good reading resource on this topic or perhaps explain shortly how is this best done?
Video tutorial from microsoft asp.net team : http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-multi-lingual-site-with-localization
Here is another useful link : http://weblogs.asp.net/sreejukg/archive/2010/11/23/multi-lingual-web-applications-using-asp-net-4.aspx
The articles that were listed in the other answers are all great resources.
Here is a quick summary of some things to consider:
Any static text that will be "user facing" should be stored in resource files. In ASP .NET these files typically take the form of .resx files where the name of the file corresponds to the name of the page in which it is consumed. There are plenty of great articles out there for how to create and maintain these files. For each new language needed, you create a separate ..resx file. So if your "default" English text for a page is stored in 'MyPage.aspx.resx', you would store the Brazilian Portuguese translation in 'MyPage.aspx.pt-BR.resx'.
When creating your "default" resource entries (sometimes referred to as messages), it's important to try and keep your messages organized as complete sentences/thoughts, as those will be easier to translate to other languages. There are some great general guidelines for structuring localizable messages on the mediawiki.org site: MediaWiki - Internationalization Hints
You'll want to be very careful with respect to things like date and number parsing and formatting. The .NET framework provides good facilities for parsing and formatting dates and numbers in a variety of different cultural contexts. Most .Parse and .Format methods accept an instance of the CultureInfo class that it can use to inform .NET about how the number or date should be formatted.
Related to the above: I've found it easier to prefer ISO-friendly date formats whenever possible. Most people that see: '2010-03-05' would know that it represents March 5, 2010 while '03-05-2010' could be interpreted as March 5, 2010 or May 3, 2010, depending on where you're from. Again, the .NET framework provides facilities for you to properly format this date based on the culture preferences of the current user, but I've often found it easier to just pick a standard format that is internationally recognized whenever possible to make your life easier.
These are very high-level guidelines and there are a lot of other things to take into consideration when localizing software. I definitely recommend that you check out the articles linked in other answers, but some of the stuff I've listed above have bitten me in the past.
The .Net Framework supports Internationalization API which is known as Globalization and Localization. Globalization/Localization includes the country/region, calendars, number format, currency format, date format, resources, text encoding etc. Have a look at MSDN article on ASP.NET Globalization and Localization

what do you call a date/time with a T in the middle (2008-09-18T00:00:00)?

If you have a date like '2008-09-18T00:00:00' does it have a name? UTC? Something like that? Surprisingly hard to google for this...
That is a combined date/time representation as defined by ISO8601. It often has a timezone/offset appended to it, e.g. 2008-09-18T00:00:00Z would denote UTC time.
That looks like RFC 3339.
ISO 8601 is also relevant: Link
Also might be ISO-8601.
Technically, that is ISO 8601, but Google refer to this simply as the "ISO date format" on this support page, as do a lot of other people (including me) seeing as it's a very popular standard. It's the top result if you google "iso date format".

Resources