Friday, July 23, 2004
Seconds since the Unix epoch in C#
Please find the code below to convert currentdatetime to epoch time in c#
public long GetEpochTime()
{
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}
With Best Regards,
Mitesh Mehta
miteshvmehta@gmail.com
public long GetEpochTime()
{
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 8:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);
long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}
With Best Regards,
Mitesh Mehta
miteshvmehta@gmail.com