WCF: Is there a way to return different datetime serialization based on the http Accept-Language header?
I would like my REST 开发者_如何学Cservice to return a DateTime as:
- 01-dec-2009 for Accept-Language: en-US
- 01-dez-2009 for Accept-Language: pt-BR
Thanks!
André Carlucci
I would argue that "serialization" means "converting something to text format for interchange/storage" and not to present to a human reader.
By this definition, it must be language independent, and follow the XML serialization convention, or ISO 8601, or a CultureInfo::InvariantCulture. See also http://www.mihai-nita.net/article.php?artID=20051025a
If we don't call it "serialization" then
How are you serializing those DateTimes?
It looks to me like they've been converted to strings, in which case you should be able to inspect the Request.UserLanguages property and inject the appropriate CultureInfo into an ordinary string.Format() call.
The standard XML serializer uses a culture-agnostic format explained here:
The dateTime is specified in the following form "YYYY-MM-DDThh:mm:ss" where:
- YYYY indicates the year
- MM indicates the month
- DD indicates the day
- T indicates the start of the required time section
- hh indicates the hour
- mm indicates the minute
- ss indicates the second
Note that these should be in UTC.
精彩评论