473,387 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Keeping datetime culture invariant

Is there a way to keep datetime expressions culture invariant? My app
is culture dependent and contains a series of datetime settings that
are saved in cookies. The cookie date strings raise exceptions when
they are read back since they won't be recognized in certain cultures
(ie US MM/DD/YY vs EU DD.MM.YY)? Currently, I track the culture state,
but this is cumbersome.

Is there a simple way to force the run-time to keep all dates in a
single format regardless of the culture state? I would like to avoid
erasing all cookies on culture change.

TIA for any hints. (ASP.NET 3.5)
Sep 22 '08 #1
2 3859
helveticus wrote:
Is there a way to keep datetime expressions culture invariant? My app
is culture dependent and contains a series of datetime settings that
are saved in cookies. The cookie date strings raise exceptions when
they are read back since they won't be recognized in certain cultures
(ie US MM/DD/YY vs EU DD.MM.YY)? Currently, I track the culture state,
but this is cumbersome.

Is there a simple way to force the run-time to keep all dates in a
single format regardless of the culture state? I would like to avoid
erasing all cookies on culture change.

TIA for any hints. (ASP.NET 3.5)
I recommend keeping to the ISO 8601 standard for culture independent
dates. It's unambiguos, so there is minimal risk that it's misunderstood.

Use the string "yyyy-MM-dd" to format and parse dates:

string formatted = someDateTime.ToString("yyyy-MM-dd");

DateTime parsed = DateTime.ParseExact(someString, "yyyy-MM-dd",
CultureInfo.InvariantCulture);

--
Göran Andersson
_____
http://www.guffa.com
Sep 23 '08 #2
Thanks! Completely forgot about the .InvariantCulture property.
Sep 23 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Li Weng | last post by:
Hi, When I retrieve urn:schemas:httpmail:date field, how do I set the format from VB.net code? I assume I should have several DateTime formats to choose from. Or is there any VB.net class to...
9
by: Iwan Petrow | last post by:
Hi, I have a string which represent a date as follow: "dd-.MM-.yyyy hh:mm". How could I convert this string to DateTime type (I prefer somehow to set this as a pattern if it is possible because...
1
by: Doug Swanson | last post by:
I'm trying to get a datetime value (10/24/2001 6:00 AM) to display as 10/24/01 6:00. I know I could hard code some format but I'm trying to use the culture info etc. so that (and this is my...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
6
by: Jack Russell | last post by:
WriteLine always seems to use commas as separators regardless of the current culture. If this is true is there an alternative which is culture sensitive or do I have to do it the long way? ...
9
by: Simon Harvey | last post by:
Hi all, I'm having a bit of a problem working with dates. My computer is british, but I'm developing an american application so I therefore need to use american dates. But I can't get my...
5
by: =?Utf-8?B?RmFlc3NsZXIgR2lsbGVz?= | last post by:
Hello, I'm facing a strange problem. We have an Asp.net 2.0 Web Application and somehow the date format is changing from one client to another even if all the code is running server-side... ...
14
by: Arjen | last post by:
Hi, I have a string with this value 07/11/2008. As you see no time included. How can I parse this string to a datetime variable? I tried to do this but I get the exception that the format is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.