jonnyboy69
asked on
Timestamp in milliseconds
I need to create the following to integrate with a system:
"Date and time expressed as the number of milliseconds elapsed since January 1, 1970 00:00:00 GMT."
How would I do this assuming the time was DateTime.Now?
Thanks
"Date and time expressed as the number of milliseconds elapsed since January 1, 1970 00:00:00 GMT."
How would I do this assuming the time was DateTime.Now?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Actually got it thanks, needed: ts.TotalMilliseconds
ASKER
Hmm this is giving me incorrect results actualy
// Timespan
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = DateTime.Now;
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
sTimeStamp = ts.TotalMilliseconds.ToStr ing();
I am getting for example:
1139977698718.75
Dont unerstand what the decimal point is about, surely milliseconds are lowest common denominator?
Thanks
// Timespan
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = DateTime.Now;
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
sTimeStamp = ts.TotalMilliseconds.ToStr
I am getting for example:
1139977698718.75
Dont unerstand what the decimal point is about, surely milliseconds are lowest common denominator?
Thanks
The smallest unit of time is the tick, which is equal to 100 nanoseconds. That is why wne you convert to milliseconds, decimal gets in.
ASKER
string sTimeSpan = "";
DateTime d1 = new DateTime(1970, 1, 1);
DateTime d2 = DateTime.UtcNow;
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
sTimeSpan = ts.Milliseconds.ToString()