• Recent Posts

  • Meta

  • Tags

    #ziplib .net getfilename .net no titlebar 7-zip adding a splash screen in visual basic.net adding textbox autocomplete addition adjusttokenprivileges adware application filename application position applications path audio library autocomplete autocomplete combobox avi mpg basic math bass.dll bass sound system beep benchmark data calculator cdrom tray change unix to windows directory exists disable beep on enter doevents excel file exists getinputstate high cpu usage linq mcisendstring no doevents open webpage pinging play mp3 play wave scroll textbox shell stop beep on enter textbox vb ping visual studio windows mci
  • Home | »

    Convert from UNIX Date/Time to Structured Windows Time (Updated!)

    By admin | February 2, 2007

    Click Star to Rate Post
    1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...


       
    Bookmark and Share

     


     
      At some point you may get a time value that is based on the Unix time format. Once you understand how Unix time is setup, its easy to deal with and display as a normal structured Date/Time in Windows. The value returned from Unix time is the amount of seconds that have taken place since January 1st 1970. So just setup a new Date passing the 01/01/1970 value and add to it the unix value in seconds. The code below is in VB.NET but the principals apply to VB 5.0/6.0 and all other versions of Visual Basic.NET. A example is below...

    '

    'The Unix time you want to convert.

    Dim x As Double = 1089316377

    'Setup a new DateTime starting at Jan 1st 1970.

    Dim d As New DateTime(1970, 1, 1)

    '

    'Then just add the Unix value to the DateTime variable as seconds.

    d = d.AddSeconds(x)

    '

    'Display the structured time value.

    MsgBox(d.ToString)

       

    Below is the results...

       

    Edit: (Feb. 2nd 2008) - I want to thank Premek for commenting on this code returning the time in UTC/GMT based time. (Universal Time Coordinated (or Coordinated Universal Time); GMT = Greenwich Mean Time) So therefore you will want to adjust the value based on your local time. Example: The Messagebox screenshot image above shows the time as UTC. If your local time is the Eastern Standard Timezone, then you would want to Subtract -5 Hours from that time. So, if the time is 7:52:57 in UTC Time, then the time for the Eastern Standard Time Zone (Not Daylight Savings) would be: 2:52:57. Below is a small chart for the United States based Time Zones. Click on this link for more information on UTC/GMT based Times...

      

    ------------------------------------------------------------------------

      

    Local Time Subtract from UTC:
    Atlantic Standard
    Four hours (-4)
    Atlantic Daylight
    Three hours (-3)
    Eastern Standard
    Five hours (-5)
    Eastern Daylight
    Four hours (-4)
    Central Standard
    Six hours (-6)
    Central Daylight
    Five hours (-5)
    Mountain Standard
    Seven hours (-7)
    Mountain Daylight
    Six hours (-5)
    Pacific Standard
    Eight hours (-8)
    Pacific Daylight
    Seven hours (-7)
    Alaskan Standard
    Nine hours (-9)
    Alaskan Daylight
    Eight hours (-8)
    Hawaiian Standard
    Ten hours (-10)

        

    ------------------------------------------------------------------------

       

      Thats all there is to it! I needed to convert unix time for a new Yahoo Search Example I will be bringing out shortly at my http://www.vbcodesource.com/ page and figured someone else may want to know the same when converting from Unix time. Have Fun!

                    Jason

     


     

    Topics: - (.5.0/6.0), - (.NET All + 05/08), - .All VB (Related to All) | 2 Comments »

    2 Responses to “Convert from UNIX Date/Time to Structured Windows Time (Updated!)”

    1. Premek Says:
      February 1st, 2008 at 11:37 am

      This is correct for UTC time only. If you are in other time zone you have to correct the hours!

    2. Jason Says:
      February 2nd, 2008 at 2:34 am

      Yes! You are correct. I definitely should have mentioned that. Thankyou for pointing that out. :)

      Jason

    Comments