Convert DateTime to Unix time in C#
I’ve been asked recently by a few people how to convert Unix time to DateTime format (and the other way around) so I decided to make a post about it explaining how Unix time works and provide a snippet to help people that want to convert DateTime to Unix time or vise versa.
Unix time is basically the number of seconds that have passed since 1/1/1970 00:00:00 (UTC). In order to convert a specific date and time to a Unix time value we will need to subtract the date above from the date we want to convert to Unix time.
Example:
1 2 3 4 5 6 7 8 9 10 11 | /// <summary> /// Convert a date time object to Unix time representation. /// </summary> /// <param name="datetime">The datetime object to convert to Unix time stamp.</param> /// <returns>Returns a numerical representation (Unix time) of the DateTime object.</returns> public static long ConvertToUnixTime(DateTime datetime) { DateTime sTime = new DateTime(1970, 1, 1,0,0,0,DateTimeKind.Utc); return (long)(datetime - sTime).TotalSeconds; } |
Now if we want to convert a Unix time value to a DateTime object the the principle is the same. We take the 1/1/1970 00:00:00 (UTC) date and add the value of the Unix time as seconds to that date. The result would be the actual DateTime of the Unix time stamp.
Example:
1 2 3 4 5 6 7 8 9 10 | /// <summary> /// Convert Unix time value to a DateTime object. /// </summary> /// <param name="unixtime">The Unix time stamp you want to convert to DateTime.</param> /// <returns>Returns a DateTime object that represents value of the Unix time.</returns> public static DateTime UnixTimeToDateTime(long unixtime) { DateTime sTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); return sTime.AddSeconds(unixtime); } |
Microsoft Visual Studio 2013 Update 2 is now available
Microsoft has released update 2 for Visual Studio 2013. The new update contains various fixes that address bugs, performance and reliability improvements.
With the new update Microsoft also created an iso image that contains Visual Studio 2013 as well as all the updates up to and including the update 2. The iso file is 3.5GB and can be downloaded from http://go.microsoft.com/fwlink/?LinkId=393220.
Here are some of the new capabilities that are part of this update:
- Universal Apps – With this release you can now build universal apps that can run on Windows 8.1 and Windows Phone 8.1 while sharing code and assets through shared projects.
- TypeScript – The TypeScript language is a typed superset of JavaScript that compiles to plain JavaScript. As a typed language you can define classes, modules and interfaces that compiles to JavaScript and runs in any browser.
- Web Tool – Our web development tools have many new features like SCSS support, a new JSON editor, updated ASP.NET templates, and an improved URL picker.
- Azure tools – It’s easier to take advantage of Azure with options to create websites and SQL Azure databases directly on Azure for simpler deployment to a development / testing environment.
- Diagnostics – Our diagnostics tools also got some enhancements. Performance events now let you navigate to user code for MVC Methods or jump to the SQL command for database queries. It is also possible to view the Windows Store diagnostics tools at the same time to see all your diagnostics information on a shared timeline.
- Slipstream install – You can download Visual Studio with all its latest features from one install that includes Visual Studio 2013 RTM and Update 2 for Visual Studio.
You can download the new Visual Studio 2013 Update 2 using the download button below.
Download
Posted in Microsoft, Software Updates.
Tagged Microsoft, Visual Studio 2013
Microsoft .NET Framework 4.5.2 is now available
Microsoft .NET Framework 4.5.2 is now available to download for free.
The Microsoft .NET Framework 4.5.2 is a highly compatible, in-place update to the Microsoft .NET Framework 4, Microsoft .NET Framework 4.5 and Microsoft .NET Framework 4.5.1.
The .NET Framework 4.5.2 contains a variety of new features, such as:
- ASP.NET improvements
- High DPI Improvements
- Distributed transactions enhancement
- More robust profiling
- Improved activity tracing support in runtime and framework
The new version of the .NET Framework can be installed on the following operation systems:
- Windows 7 Service Pack 1
- Windows 8
- Windows 8.1
- Windows Vista Service Pack 2
- Windows Server 2008 R2 SP1
- Windows Server 2008 Service Pack 2
- Windows Server 2012
- Windows Server 2012 R2
Use the download button below to download the offline installer (66.8 MB) for Microsoft’s .NET Framework 4.5.2
Download
Posted in Microsoft, Software Updates.
Tagged .NET, .NET Framework, .NET Framework 4.5.2, Microsoft
Windows 8.1 Update 1 is now available to download
Windows 8.1 update 1 (also known as KB 2919355) has been made available to download for free through the Windows update feature and the Microsoft’s download section.
If you are planning to install the update by downloading the files through Microsoft’s website make sure that you have the KB 2919442 patch already installed as it is required in order to install the new update.
On other other hand, if you are installing the patch through the Windows update feature there is a high chance that you have already installed the patch by now.
The update is designed to improve the Windows interface as well as the functionality for keyboard and mouse users. For more detailed information visit Exploring Windows 8.1 Update.
Download Links:
Posted in Microsoft, Software Updates.
Tagged Microsoft, Windows, Windows 8.1
QR Workshop – A portable QR code reader and generator
QR Workshop is a free, open source and portable application that allows you to generate QR codes of your choice.
As you can see below the interface is minimal and very simple to use. In order to generate a QR code you simply need to specify the dimensions (width and height) of the image you would like to create and enter the text that will be encoded in the QR code image itself. Then simply press generate and save the image.
QR Workshop can also be used as a QR code reader which allows you to decode and display the information that is encoded within a QR code image. In order to do that you have to switch to the QR Code Reader tab, drag&drop the QR code image in the text field or simply click the browse button next to it in order to open the file browser which you can use to select one. Finally after you have selected the image of your liking click Decode.
QR Workshop requires Microsoft .NET Framework 3.5 and Windows XP or higher in order to run properly.
Posted in Software Releases.
Tagged fluxbytes, fluxbytes software, QR code, QR Workshop