How to deal arabic datetime formats problem ?


in this article , I will explain a better way to handle arabic datetime issues and any other datetime issues using datetime ticks ,this way is so simple and reduce complications and conflicts in code

many developers faced problems dealing with datetime formats specially arabic datetime but i find that we can avoid this problem using datetime ticks

we can make use of it in the follwing issues :

1- Compare two date Times :


DateTime _DateTimeFrom = new DateTime(2011, 2, 1);
DateTime _DatTimeTo = new DateTime(2011, 2, 27);
if (_DateTimeFrom.Ticks <_DatTimeTo.Ticks)
{
//Do Somthing
}



2- Saving DateTime object
you can save object to file without making any condition for datetime formats or Parsing strings Using the Following Code :


//save DateTime to file
DateTime _DateTimeObjToWrite = new DateTime(2011, 2, 1);
using (StreamWriter _StreamWriter = new StreamWriter(@"c:\tempFile.txt"))
{
_StreamWriter.Write(_DateTimeObjToWrite.Ticks);
}
//Read From File
using (StreamReader _StreamReader = new StreamReader(@"c:\tempFile.txt"))
{
DateTime _DateTimeObjToRead= new DateTime(long.Parse(_StreamReader.ReadLine()));
}


hope this helps
Thanks


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: