Reputation: 28586
Imagine an abstract problem.
There is a client (C
) that interacts to a server(S
). They changes a date variable(d
).
A server can be French or English, the client too.
A date sent by a French client ("31/12/2011") to an English Server("12/31/2011") can't recognize it. And viceversa.
How to avoid such a problem in .NET.
Upvotes: 2
Views: 699
Reputation: 289
Is there any reason why you are sending the date as string? The best thing would be to share the date using DateTime datatype. If for any reason, you can just send the string, best is to convert the date value to LongDateFormat and then transfer, which could be parsed on the other end to get the meaningful date.
Upvotes: 0
Reputation: 5081
Send it between the client and server using the Ticks property. That's a number and will always be the same no matter what you want to format the date as.
Upvotes: 1
Reputation: 1500875
Are you in control of both the client and the server? If so, just agree on a format and culture - I'd suggest the invariant culture - and explicitly make sure that both sides adhere to it.
You can very easily parse and format in .NET using the invariant culture - look for ToString
and Parse
/TryParse
overloads which include an IFormatProvider
parameter.
Upvotes: 4