Results 1 to 5 of 5

Thread: [RESOLVED] Converting non-US date string to date object

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Resolved [RESOLVED] Converting non-US date string to date object

    I'm saving a date to a JSON file as a string using Date.Now.ToString & then reading it back in & converting to a date at startup using CDate(myDateStr) which works fine, except when somebody from a non-US country runs my app the date is written as "Thu 15 02 2024 22:38:32" & when I try to convert that string to a date I'm getting an error "String was not recognized as a valid DateTime." How can I make my code handle both a US format ("mm:dd:yy hh:mm:ss") & non-US format "Thu 15 02 2024 22:38:32"? Do I need to specify the format when I write it so it's always saved in a consistant format or is there a better way? Thanks...

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Converting non-US date string to date object

    IIRC just saving it as a date, without converting to a string, should work.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Converting non-US date string to date object

    That's interesting. I didn't know you could do that. So when I don't convert to a string it gets saved as "2024-02-18T12:04:30.5186749-05:00". It looks like it's more of a universal date/time format. So when I read that back in & convert to a date object will it display in the format of the users localization setting?

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,958

    Re: Converting non-US date string to date object

    Once it has been deserialised to a date then it will behave based on the normal date behaviour. It should indeed reflect the user's locale settings.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2006
    Location
    MI
    Posts
    2,012

    Re: Converting non-US date string to date object

    Thanks PD...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width