0

I would like my REST service to return a DateTime as:

  • 01-dec-2009 for Accept-Language: en-US
  • 01-dez-2009 for Accept-Language: pt-BR

Thanks!

André Carlucci

Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95
andrecarlucci
  • 5,927
  • 7
  • 52
  • 58

2 Answers2

1

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

Mihai Nita
  • 5,547
  • 27
  • 27
0

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.

Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95