G
Guest
Hi..
I'm writing a web service in C# and needs to produce some time_t values in the xml output, and near as I can figure there appears to be a bug in the C# datetime arithmetic. Below is an example in asp.net using the JScript Date object to demonstrate the bug. The net problem is that the number of seconds calculation ends up an hour off (an extra hour). If anyone can point out a better way to run the calculation I'd apprecitate it
Thanks
-Mar
timebug.aspx
<%@Language="C#" EnableSessionState="false"%><script language="C#" runat="server"
void PrintCSDate (
DateTime now = DateTime.Now, t_base = DateTime.Parse("Thu, 1 January 1970 00:00:00 GMT")
TimeSpan tt = now - t_base
double update_time = System.Math.Floor (tt.TotalSeconds)
Response.Write ("Now: "+now+"<br>\n")
Response.Write ("Seconds (time_t): "+update_time+"<br>\n")
Application ["tbugSeconds"] = (long) update_time; // pass seconds in Applicatio
DateTime ttnow = t_base.AddSeconds (update_time)
Response.Write ("TTNow: "+ttnow+"<br>\n")
</script><
PrintCSDate()
Server.Transfer ("timebugj.aspx")
%
timebugj.aspx
<%@Language="Jscript" EnableSessionState="false"%><script language="Jscript" runat="server"
function PrintJDate (
{ var secs = Application ["tbugSeconds"]*1000; // get offset from C# cod
var d = new Date (secs)
Response.Write ("JDate: "+d+"<br>\n")
</script><% PrintJDate(); %>
I'm writing a web service in C# and needs to produce some time_t values in the xml output, and near as I can figure there appears to be a bug in the C# datetime arithmetic. Below is an example in asp.net using the JScript Date object to demonstrate the bug. The net problem is that the number of seconds calculation ends up an hour off (an extra hour). If anyone can point out a better way to run the calculation I'd apprecitate it
Thanks
-Mar
timebug.aspx
<%@Language="C#" EnableSessionState="false"%><script language="C#" runat="server"
void PrintCSDate (
DateTime now = DateTime.Now, t_base = DateTime.Parse("Thu, 1 January 1970 00:00:00 GMT")
TimeSpan tt = now - t_base
double update_time = System.Math.Floor (tt.TotalSeconds)
Response.Write ("Now: "+now+"<br>\n")
Response.Write ("Seconds (time_t): "+update_time+"<br>\n")
Application ["tbugSeconds"] = (long) update_time; // pass seconds in Applicatio
DateTime ttnow = t_base.AddSeconds (update_time)
Response.Write ("TTNow: "+ttnow+"<br>\n")
</script><
PrintCSDate()
Server.Transfer ("timebugj.aspx")
%
timebugj.aspx
<%@Language="Jscript" EnableSessionState="false"%><script language="Jscript" runat="server"
function PrintJDate (
{ var secs = Application ["tbugSeconds"]*1000; // get offset from C# cod
var d = new Date (secs)
Response.Write ("JDate: "+d+"<br>\n")
</script><% PrintJDate(); %>