Search results for 'DateTime Conversion'. 1 post(s) found.

  1. 2008/09/22 Convert System.DateTime to UNIX timestamp
2008/09/22 10:23

Convert System.DateTime to UNIX timestamp


In case of development in clinet/server application, datetime formation conversion is frequently required.
Following is the simple example for DateTime Conversion.

private double ConvertToTimestamp(DateTime value)
{
    //create Timespan by subtracting the value provided from
    //the Unix Epoch
    TimeSpan span = (value - new DateTime(1970, 1, 1, 0, 0, 0, 0).ToLocalTime());

    //return the total seconds (which is a UNIX timestamp)
    return (double)span.TotalSeconds;
}
Trackback 0 Comment 0

Trackback : Cannot send a trackbact to this post.