Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 131,924 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,678 people online right now. Registration is fast and FREE... Join Now!





Convert System.DateTime to UNIX timestamp

Snippet to convert a DateTime value to a UNIX Timestamp

Submitted By: PsychoCoder
Actions:
Rating:
Views: 2,269

Language: C#

Last Modified: June 30, 2008

Snippet


  1. /// <summary>
  2. /// method for converting a System.DateTime value to a UNIX Timestamp
  3. /// </summary>
  4. /// <param name="value">date to convert</param>
  5. /// <returns></returns>
  6. private double ConvertToTimestamp(DateTime value)
  7. {
  8.     //create Timespan by subtracting the value provided from
  9.     //the Unix Epoch
  10.     TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());
  11.  
  12.     //return the total seconds (which is a UNIX timestamp)
  13.     return (double)span.TotalSeconds;
  14. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month