Tag Archives: change unix to windows

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

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.
Here are 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 TimeSubtract 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 made and figured someone else may want to know the same when converting from Unix time. Have Fun!