Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / April 2007

Tip: Looking for answers? Try searching our database.

Need Help: DateTime.Parse CultureInfo Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kilaen@gmail.com - 05 Apr 2007 20:46 GMT
I have this method that converts dates from a culture of origin to a
destination culture. It's not working as intended, hopefully someone
can enlighten me and tell me what I'm doing wrong. I've included the
code, the values being passed in, and the output. Thanks in advance!

value = "01/04/2007 12:30:48"
selected = {en-GB}
origin = {en-GB}
to = {en-US}
result = {1/4/2007 12:30:48 PM}

I expected to see: {4/1/2007 12:30:48PM}

public static DateTime ConvertDateTime(string value, CultureInfo
selected, CultureInfo origin, CultureInfo to)
{
    DateTime result;
    try
    {
        result = DateTime.Parse(value, to);
    }
    catch (Exception)
    {
        result = DateTime.Parse(value, selected);
    }
    return result;
}
Göran Andersson - 06 Apr 2007 00:19 GMT
> I have this method that converts dates from a culture of origin to a
> destination culture.

No, it does not. It parses the text representation of a date from one of
two cultures into a DateTime value. A DateTime value is culture neutral.

> It's not working as intended, hopefully someone
> can enlighten me and tell me what I'm doing wrong. I've included the
[quoted text clipped - 5 lines]
> to = {en-US}
> result = {1/4/2007 12:30:48 PM}

You are parsing the date using the en-US culture. What culture have you
used to create the textual representation of the result?

> I expected to see: {4/1/2007 12:30:48PM}
>
[quoted text clipped - 12 lines]
>     return result;
> }

Signature

Göran Andersson
_____
http://www.guffa.com


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.