Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
|
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2009, 08:32 AM
Authorized User
 
Join Date: Nov 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Hi, need small but urgent help plzz

Hey,
There is a issue for date. I am using DateTime.Now(). At local it gives me exact date and time for my pc but after upload it provides me our server date which have a difference of 5 hours 50 minutes before our time. I just need a code which can take current system time. Like if a user is doing entries at some other place, only his system time come not the SERVER time.

Regards and Thanks,
Rajat Bhalla
 
Old December 1st, 2009, 02:56 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

as you said 'server date have a difference of 5 hours 50 minutes before our time' you can write a function that uses DateTime.Now() and adds 5:50 to it and returns new value. and if You are professional you can write a class like this

public static class Tu6tY
{
public static DateTime myNow(this DateTime dt)
{
return (dt.Now() - DateTime.Parse("5:50:0"));
}
}

and now you can use this code in your program:

DateTime.myNow();
 
Old December 1st, 2009, 03:29 AM
Authorized User
 
Join Date: Nov 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thanks but not the perfect solution

Well, this code will work for my country only but what about other countries?? I need a enter particular user's system date.:)
 
Old December 1st, 2009, 03:36 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

change the code of myNow function to convert your server time to GMT because time in every country is different to other, and GMT is standard time all over the world
 
Old December 1st, 2009, 06:32 AM
Authorized User
 
Join Date: Nov 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default Thankyou very much,

I have achieved date issue with javascript date. It picks every user's browser date.

Thanks a lot
 
Old December 1st, 2009, 08:25 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

you can get GMT time using ajax technology from a server. I can tell you how to perform this later, tomorrow i'll send it. I'm going ...
 
Old December 1st, 2009, 10:32 AM
Authorized User
 
Join Date: Nov 2009
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
Default thanks

This would be wonderful. Thanks a alot
 
Old December 3rd, 2009, 04:37 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

check out this post. There is a nice javaScript solution that is very easy to implement and understand.
 
Old December 7th, 2009, 02:17 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default

you can send a request to my page located in http://[email protected]/services/getTime.aspx using this javascript code:
Code:
<script type="text/javascript">
function createXHR()
{
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   
   alert("XMLHttpRequest not supported");   
   return null;
}

function sendRequest_getTime()
{
	var xhr = createXHR();
	if(xhr)
	{
		var url = "http://aspnet35.brinkster.net/services/getTime.aspx";
		xhr.open("GET", url, true);
		xhr.onreadystatechange = function(){handleResponse_getTime(xhr);};
		xhr.send(null);
	}
}
function handleResponse_getTime(xhr)
{
  	if (xhr.readyState == 4  && xhr.status == 200)
    {
     var parsedResponse = xhr.responseText;
     var responseOutput = document.getElementById("div_time");
     responseOutput.innerHTML = parsedResponse;
    }
}
}
</script>
to work with above javascript codes add a div tag in your page named div_time and you can use following code to get time:
Code:
<div id="div_time"></div>
<input type="button" onclick="sendRequest_getTime();" />





Similar Threads
Thread Thread Starter Forum Replies Last Post
Some help plzz pauyo BOOK: ASP.NET Website Programming Problem-Design-Solution 1 September 30th, 2006 10:34 PM
plzz Help therisingsun ASP.NET 1.0 and 1.1 Basics 3 September 5th, 2005 01:50 AM
plzz help me shami J2EE 0 August 24th, 2003 11:02 AM
plzz help me shami Java Databases 0 August 24th, 2003 11:00 AM
plzz help me shami Classic ASP Databases 1 August 23rd, 2003 03:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.