Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Getting Files LastWriteTime

Getting Files LastWriteTime

Scheduled Pinned Locked Moved C#
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    narayanagvs
    wrote on last edited by
    #1

    Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using

       DateTime \_datetime;
       String str = "C:\\\\A.txt"
       FileInfo filinf = new FileInfo(str);
       \_datetime = filinf.LastWriteTime;
    

    I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya

    Today is a gift, that's why it is called the present.

    A N D 3 Replies Last reply
    0
    • N narayanagvs

      Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using

         DateTime \_datetime;
         String str = "C:\\\\A.txt"
         FileInfo filinf = new FileInfo(str);
         \_datetime = filinf.LastWriteTime;
      

      I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya

      Today is a gift, that's why it is called the present.

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      I think you should use Globalization For that. User RegionInfo Class and Try to use the date time from that class. This is just my idea !!!

      Best Regards ----------------- Abhijit Jana Microsoft Certified Professional "Success is Journey it's not a destination"

      1 Reply Last reply
      0
      • N narayanagvs

        Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using

           DateTime \_datetime;
           String str = "C:\\\\A.txt"
           FileInfo filinf = new FileInfo(str);
           \_datetime = filinf.LastWriteTime;
        

        I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya

        Today is a gift, that's why it is called the present.

        N Offline
        N Offline
        narayanagvs
        wrote on last edited by
        #3

        I got the solution

        FileInfo filinf = new FileInfo(FileName);
        _datetime = filinf.LastWriteTime;

        DaylightTime dlt = TimeZone.CurrentTimeZone.GetDaylightChanges(_datetime.Year);
        //String strHrs = dlt.Delta.Hours.ToString();
        _datetime = _datetime.AddHours(Convert.ToDouble(dlt.Delta.Hours));
        _datetime = _datetime.AddMinutes(Convert.ToDouble(dlt.Delta.Minutes));
        _datetime = _datetime.AddSeconds(Convert.ToDouble(dlt.Delta.Seconds));

        Thanks

        Today is a gift, that's why it is called the present.

        L 1 Reply Last reply
        0
        • N narayanagvs

          I got the solution

          FileInfo filinf = new FileInfo(FileName);
          _datetime = filinf.LastWriteTime;

          DaylightTime dlt = TimeZone.CurrentTimeZone.GetDaylightChanges(_datetime.Year);
          //String strHrs = dlt.Delta.Hours.ToString();
          _datetime = _datetime.AddHours(Convert.ToDouble(dlt.Delta.Hours));
          _datetime = _datetime.AddMinutes(Convert.ToDouble(dlt.Delta.Minutes));
          _datetime = _datetime.AddSeconds(Convert.ToDouble(dlt.Delta.Seconds));

          Thanks

          Today is a gift, that's why it is called the present.

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, you have a problem with FileInfo.LastWriteTime? if you read the documentation, you should notice the very next item in MSDN is FileSystemInfo.LastWriteTimeUtc :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.


          1 Reply Last reply
          0
          • N narayanagvs

            Hi, I need to get the Files last Modified Date.Iam given a Zip File by our client on extracting it I get many files, say I got a File A.txt. whose modified date is 2/19/2008 06:30:00 A.M. Iam using

               DateTime \_datetime;
               String str = "C:\\\\A.txt"
               FileInfo filinf = new FileInfo(str);
               \_datetime = filinf.LastWriteTime;
            

            I get the correct output in _datetime. Now , If I change my System TimeZone from ( GMT +5:30)chennai... to (GMT -8:00)Pacific Time (US & Canada) and then again extract the Zip file to get file "A" with modified date as 2/19/2008 06:30:00 A.M and execute the same code I get it as 2/20/2008 05:30:00 A.M. Why is it So?There is an offset of 1 hour. I need Files Last Modified Date(say here 2/19/2008 06:30:00 A.M only) Irrespective of TimeZones Iam In. Any suggestions would be appreciated. Thanks Satya

            Today is a gift, that's why it is called the present.

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Use LastWriteTime**Utc** instead. The LastWriteTime property is adjusted for timezone and daylight savings time, while the UTC version is not.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups