I have come across a strange problem. MY app has been localized to support 5 languages.
It is a calendar sort of app, and i have an option of writing notes for a particular date.
So when I change my language settings to Russian, enter a note on a date, eg 1/3/2012 and on 6/3/2012. This date and note is stored in an IsolatedStorageFile and i exit the app.
Now, I change my language settings to english, and the notes are stored in 3/1/2012 and 3/6/2012. The month and date are reversed !! 🙁
This is how i write the notes to the file
using (IsolatedStorageFileStream fileStream = storagefile.OpenFile("NotesFile", FileMode.Open, FileAccess.ReadWrite))
{
StreamWriter writer = new StreamWriter(fileStream);
for (int i = 0; i < m_noteCount; i++)
{
writer.Write(m_arrNoteDate[i].ToShortDateString());
writer.Write(" ");
writer.Write(m_arrNoteString[i]);
writer.WriteLine("~`");
}
writer.Close();
}
Reading is from file is done like this
if (notes.Substring(i, 1) == " ")
{
m_arrNoteString[count] = notes.Substring(i + 1);
string temp = notes.Substring(0, i);
m_arrNoteDate[count] = DateTime.Parse(temp);
count++;
nextCharacter = (char)reader.Read();
notes = "";
break;
}
the parser reads date in a format according to language the device is set to? Any work arounds?
Alfah
By default, the conversion between dates and strings (and vice versa) uses the current culture. For your purpose, since you are not converting to/from strings for the purpose of displaying dates to the user but to persist them, you should make your logic independent of the current culture by specifying a given culture. And the invariant culture is your best best.
So replace this:
With this:
And replace this:
With this: