Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Unix Time Conversion

Posted on October 23, 2013October 26, 2015 By David Kittell

When integrating various systems you sometimes need to convert DateTime values to an Integer, the code samples below will be helpful

Public Function UnixToDateTime(ByVal strUnixTime As String) As Date
	UnixToDateTime = DateAdd(DateInterval.Second, Val(strUnixTime), #1/1/1970#)
End Function

Public Function DateTimeToUnix(ByVal dteDate As Date) As String
	DateTimeToUnix = System.Convert.ToInt64((dteDate - New DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds)
End Function
public static long DateTimeToUnix(this DateTime target)
{
	var date = new DateTime(1970, 1, 1, 0, 0, 0, target.Kind);
	var unixTimestamp = System.Convert.ToInt64((target - date).TotalSeconds);
	return unixTimestamp;
}

public static DateTime UnixToDateTime(this DateTime target, long timestamp)
{
	var dateTime = new DateTime(1970, 1, 1, 0, 0, 0, target.Kind);
	return dateTime.AddSeconds(timestamp);
}
Originally Posted on October 23, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp VB.NET

Post navigation

Previous post
Next post

Related Posts

Battery Life

Posted on May 3, 2013February 8, 2016

By its self this code is rather simple and meaningless but useful when adding to scheduled tasks or applications that take a long time to run and have the potential of running on a laptop. Before using the code below in Design View you’ll need these: 1 Progress Bar 2…

Read More

Check Instance Of Application

Posted on May 9, 2014October 26, 2015

Preferred Method: Project Menu -> Properties -> Application -> Check Box: Make Single Instance Application Non-Preferred Method: This code will look in your task manager for the same name of your application, if it exists it will prevent another copy of it from running. ‘ Make sure they only have…

Read More

UNIX Bash – Website Monitor

Posted on August 23, 2016

for i in $(curl -s -L cnn.com |egrep –only-matching ‘http(s?):\/\/[^ \"\(\)\<\>]*’ | uniq) do curl -s -I "$i" 2>/dev/null | head -n 1 | cut -d’ ‘ -f2 done curl -Is http://www.google.com | head -n 1 HTTP/1.1 200 OK curl www.websiteToTest.com -s -f -o /dev/null || echo "Website down." |…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes
 

Loading Comments...
 

You must be logged in to post a comment.